douzhi8244 2017-05-06 04:07
浏览 230
已采纳

如何调试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??

  • 写回答

1条回答

  • dongxu4023 2017-05-06 04:13
    关注

    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
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥85 maple软件,solve求反函数,出现rootof怎么办?
  • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上