Reputation: 672
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' => '[email protected]',
'name' => 'Company Name'
],
'encryption' => 'tls'),
'username' => '[email protected]',
'password' => 'xxxxd663hd02j727bb2eefd1ea38bbe0-58bc211a-670xxxx'
];
config/services.php
'mailgun' => [
'domain' => 'https://api.mailgun.net/v3/mg.domain.com',
'secret' => 'xxxxehbe8v25g3374e5as3ff32a45995-39bc661a-4716xxxx',
],
Controller
use Illuminate\Support\Facades\Mail;
$data = [
'email' => '[email protected]',
'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.
Upvotes: 10
Views: 2995
Reputation: 101
You may try Installing SwiftMailer library in your server.
sudo apt install -y php-swiftmailer
Upvotes: 0
Reputation: 1340
I struggled with this very same problem (laravel + mailgun) for a FULL DAY.
This is what ultimately solved my problem. Hope this helps!
MAIL_DRIVER=mailgun
MAILGUN_DOMAIN=mail.mydomain.com
MAILGUN_SECRET=xxxxxxxxxxxxxxxxxxxxxxxxx
[email protected]
MAIL_FROM_NAME='KP'
In routes/web.php:
Route::get('/tst', function(){
Mail::raw('Sending emails with Mailgun and Laravel is easy!', function($message)
{
$message->to('[email protected]', 'K P')->subject('Hello there, how are you?');
});
echo "string";
});
Note: you will need to make sure that your MAILGUN_DOMAIN is set and the MX / DNS records exist on your server / domain. This can take up to 24 hrs to propagate (sadly, the most annoying part). But these are all the settings you would need.
Upvotes: 0
Reputation: 950
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.
Upvotes: 12
Reputation: 3284
I'm using laravel 5.8 and it's working with all default configuration
.env
MAIL_DRIVER=mailgun
MAILGUN_DOMAIN=sandbox8a408833ad1540e7b3a5d0151f606531.mailgun.org
MAILGUN_SECRET=92df7e85eeeaccaeae3d3b3164600666-87cdd773-8c819599
web.php
Route::get('send_test_email', function(){
Mail::raw('Sending emails with Mailgun and Laravel is easy!', function($message)
{
$message->to('[email protected]');
});
});
services.php
'mailgun' => [
'domain' => env('MAILGUN_DOMAIN'),
'secret' => env('MAILGUN_SECRET'),
],
Upvotes: 0
Reputation: 1046
Try to put:
'endpoint' => env('MAILGUN_ENDPOINT', 'api.mailgun.net'),
in your mailgun
array.
Upvotes: 0