I’m working on a basic PHP script to test Mailgun email functionality, but I’m running into an issue where my script stops executing before reaching the final echo statements. The email isn’t being sent either.
Here’s my test code:
<?php
require 'vendor/autoload.php';
use Mailgun\Mailgun;
$mailgun_domain = // my domain here
echo("Starting process");
$client = new Mailgun("key-xxx");
echo("Client created");
$message_data = array(
'from' => 'Test Sender <[email protected]>',
'to' => '[email protected]',
'subject' => 'Test Message',
'text' => 'This is a test email from Mailgun!'
);
$response = $client->sendMessage($mailgun_domain, $message_data);
echo("Message sent");
echo("Process complete");
?>
I’m getting these error messages in my logs:
[Fri Dec 26 13:31:49.740756 2014] [:error] [pid 17630] [client 73.197.216.144:49648] script '/var/www/html/temp.php' not found or unable to stat
[Fri Dec 26 13:33:02.652593 2014] [:error] [pid 18741] [client 73.197.216.144:49737] PHP Fatal error: Uncaught exception 'Guzzle\Common\Exception\RuntimeException' with message 'The PHP cURL extension must be installed to use Guzzle.' in /var/www/html/vendor/guzzle/guzzle/src/Guzzle/Http/Client.php:72
The script seems to stop executing at the sendMessage call. Any ideas what might be causing this?
Looking at your error log, there are actually two separate issues happening. The first error indicates the script file itself couldn’t be found initially, but the second error is the real culprit - the missing cURL extension causing a fatal RuntimeException. What’s happening is that when your script reaches the sendMessage() call, Guzzle attempts to initialize its HTTP client but fails immediately because cURL isn’t available. This throws an uncaught exception that terminates the entire script execution, preventing any subsequent code from running. Beyond just installing php-curl, you should also consider adding proper error handling around your Mailgun calls using try-catch blocks. This way you can gracefully handle API failures and still execute cleanup code or display meaningful error messages to users instead of having your script die silently.
sounds like you need the curl ext installed. try running sudo apt-get install php-curl or get ur host to turn it on. this is a common bump with mailgun as it relies on curl for sending requests.
The error message is pretty clear about what’s happening here. Your PHP installation is missing the cURL extension which Mailgun’s underlying HTTP library (Guzzle) requires to make API calls. When the script hits the sendMessage line, it throws a fatal exception and terminates execution, which is why you never see your final echo statements.
After installing the cURL extension, make sure to restart your web server. You can verify it’s working by running php -m | grep curl from command line or checking phpinfo() output. I encountered this exact same issue when first setting up Mailgun on a fresh server installation. The script will run normally once cURL is properly enabled.