Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug laravel mailgun

I'm trying to set up mailgun with laravel (5.4) and it's sounds so easy with the docs, but getting it to actually work has been a nightmare and I'm not even sure how to debug the issue.

Here's my situation:

I have guzzle installed.

I can successfully send an email via cURL from my server.

In my config/services.php file I have:

'mailgun' => [
    'domain' => env('MAILGUN_DOMAIN'),
    'secret' => env('MAILGUN_SECRET'),
]

which I have set in my .env file with:

MAILGUN_DOMAIN=https://api.mailgun.net/v3/sandbox...a.mailgun.org
MAILGUN_SECRET=key-926d...746

The driver defaults to mailgun in config/mail.php (I even have it set in my .env file anyways):

'driver' => env('MAIL_DRIVER', 'mailgun')

I have verified my email as an Authorized Recipients in MailGun.

When I log the env values on my server, they are what I am seeing in my .env file.

I've cleared my config cache via php artisan config:clear every time I try a change.

When I go to send mail in a try/catch I get no errors. When I check Mail::failures(); I get nothing.

try {
     $mailSent = Mail::raw('test', function($message) {
         $message->to('<my authorized-email>', 'name');
         $message->subject('testing');
     });
} catch (\Exception $e) {
    dd($e->getMessage());
}

$fail = Mail::failures();

if(!empty($fail)) throw new \Exception('Could not send message to '.$fail[0]);

When I set APP_DEBUG=true and APP_LOG_LEVEL=debug I still get nothing in my log.

From my understanding, I only need to set the driver, domain and secret to use mailguns API (not via smtp) so what I have above is all that I have set.

What can I do to figure out what's failing??

like image 376
Radar2004 Avatar asked May 06 '17 04:05

Radar2004


1 Answers

The MAILGUN_DOMAIN variable in your .env file should be only the domain name (instead of the API url):

Instead of

MAILGUN_DOMAIN=https://api.mailgun.net/v3/sandbox...a.mailgun.org

Use

MAILGUN_DOMAIN=sandboxXXXX.mailgun.org
like image 88
Agu Dondo Avatar answered Oct 02 '22 04:10

Agu Dondo