Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ericbarber's avatar

Mailgun driver is not functioning for me

Hello! How would I go about diagnosing issues with the Mailgun driver? I entered my domain and private API key in config/services.php and changed the "driver" entry in config/mail.php to "env('MAIL_DRIVER', 'mailgun'),". I then deleted all MAIL_ related entries in my .env file. Nothing is going through when I send a password reset email or when I attempt to send mail through a closure in my routes file:

Route::get('send_test_email', function(){
    Mail::raw('Test email from Mailgun', function($message)
    {
        $message->to('[email protected]');
    });

I have logging set to debug yet nowhere I look do I have feedback for what's happening. SMTP driver works fine, but would prefer to use the API. Any help or guidance on troubleshooting is appreciated!

edit: I have guzzlehttp/guzzle included in my composer.json file and in the vendor folder it shows that I have guzzle v 6.3 installed. I also tested my Mailgun config with cURL and it functions as expected.

0 likes
2 replies
ejdelmonico's avatar

Well, it could be a couple of things. First, clear your config cache with artisan and then make sure you have your keys correct. You can't just copy and paste the address they give because it won't unless you are using the sandbox. I usually place the driver config and all keys in my .env file. Personally, I usually do not change the keys in the config file incase a future upgrade changes them. An example would be:

MAIL_DRIVER=mailgun
MAIL_HOST=smtp.mailgun.org
[email protected]
MAIL_PASSWORD=ncnwieuhfvc78934h93934y9f9hf
MAILGUN_DOMAIN=example.com
MAILGUN_SECRET=key-mvcfiohvb8945hgvnnv93v34

And NO they are not real keys so forget about using them.

ericbarber's avatar

I was under the impression that setting the driver to "mailgun" means that the only two pieces of information Laravel needs to send an email would be the domain and the private key (just like the cURL example on Mailgun's site).

Regardless, I ran "php artisan config:clear" and added your block of code with my details and it did not work still.

Documentation says:

The API based drivers such as Mailgun and SparkPost are often simpler and faster than SMTP servers. If possible, you should use one of these drivers. All of the API drivers require the Guzzle HTTP library, which may be installed via the Composer package manager:

composer require guzzlehttp/guzzle

To use the Mailgun driver, first install Guzzle, then set the driver option in your config/mail.php configuration file to mailgun. Next, verify that your config/services.php configuration file contains the following options:

'mailgun' => [
    'domain' => 'your-mailgun-domain',
    'secret' => 'your-mailgun-key',
],

EDIT: I figured it out, it was just me not paying close enough attention. The config/services.php file came with "env()" wrapped around the domain and secret parts of the array. I blindly just copied my creds in. I removed the "env()" portion and it works beautifully.

To anyone in the future that is setting up the Mailgun API in Laravel (I'm in 5.5), all you need to do is change the driver in config/mail.php and add your domain and private key to config/services.php. It works like magic! Thanks Laravel and thank you ejdelmonico for taking the time to reply.

Please or to participate in this conversation.