Skip to content
Advertisement

Laravel – No emails sending using mailgun

Server: Digital Ocean

Ubuntu 16.04

Laravel 5.8

I cannot get email to send out of laravel using mailgun.com

In Digital Ocean I have all outgoing ports open on the firewall, I have the correct DNS settings in Digital ocean for TXT and MX records. I have the correct and verified DNS records on my domain registar and mailgun has a green checkmark on all

config/mail.php

return [
'driver' => 'mailgun',
'host' => 'smtp.mailgun.org',
'port' => 587,
'from' => [
    'address' => 'orders@domain.com',
    'name' => 'Company Name'
],
'encryption' => 'tls'),
'username' => 'orders@mg.domain.com',
'password' => 'xxxxd663hd02j727bb2eefd1ea38bbe0-58bc211a-670xxxx'
];

config/services.php

'mailgun' => [
    'domain' => 'https://api.mailgun.net/v3/mg.domain.com',
    'secret' => 'xxxxehbe8v25g3374e5as3ff32a45995-39bc661a-4716xxxx',
],

Controller

use IlluminateSupportFacadesMail;

$data = [
        'email' => 'email@yahoo.com',
        'name' => 'Bob Smith'
    ];

    $body_data = [
        'id' => '1234'
    ];

    Mail::send('emails.shipped', $body_data, function($message) use ($data)
{
    $message->to($data['email'], $data['name'])->subject('Test Email');
});

When I change mail driver to log and then check log file it looks great. Everything looks perfect and I have used mailgun before on Laravel 5.5 with no problems. I have also tried the new laravel build method and same issue.

I get no errors, I checked logs on apache2, no logs are appearing in mailgun and of course no email comes through in inbox or spam.

My question is, am I missing anything? What other troubleshooting can I do? Seems like my app isn’t connecting to mailgun correctly.

Advertisement

Answer

I think that in your config/services.php the mailgun.domain should be more like mg.domain.com (or sandboxXXXXXXX.mailgun.org if that’s a dev environment), and not a url like the one you’ve set.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement