如何调试 laravel mailgun
How to debug laravel mailgun
我正在尝试使用 laravel (5.4) 设置 mailgun,使用文档听起来很简单,但让它实际工作一直是一场噩梦,我什至不确定如何调试问题。
这是我的情况:
我已经安装了guzzle
。
我可以从我的服务器通过 cURL
成功发送电子邮件。
在我的 config/services.php
文件中我有:
'mailgun' => [
'domain' => env('MAILGUN_DOMAIN'),
'secret' => env('MAILGUN_SECRET'),
]
我在 .env
文件中设置了:
MAILGUN_DOMAIN=https://api.mailgun.net/v3/sandbox...a.mailgun.org
MAILGUN_SECRET=key-926d...746
在 config/mail.php
中驱动程序默认为 mailgun(我什至在我的 .env
文件中设置了它):
'driver' => env('MAIL_DRIVER', 'mailgun')
我已在 MailGun 中将我的电子邮件验证为授权收件人。
当我在服务器上记录 env 值时,它们就是我在 .env
文件中看到的值。
每次尝试更改时,我都会通过 php artisan config:clear
清除我的配置缓存。
当我在 try/catch
中发送邮件时,我没有收到任何错误。当我检查 Mail::failures();
时,我什么也没得到。
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]);
当我设置 APP_DEBUG=true
和 APP_LOG_LEVEL=debug
时,我的日志中仍然没有任何结果。
根据我的理解,我只需要设置驱动程序、域和密码即可使用 mailguns API(不是通过 smtp)所以我上面的就是我设置的所有内容。
我该怎么做才能找出失败的原因??
.env 文件中的 MAILGUN_DOMAIN 变量应该只是域名(而不是 API url):
而不是
MAILGUN_DOMAIN=https://api.mailgun.net/v3/sandbox...a.mailgun.org
使用
MAILGUN_DOMAIN=sandboxXXXX.mailgun.org
我正在尝试使用 laravel (5.4) 设置 mailgun,使用文档听起来很简单,但让它实际工作一直是一场噩梦,我什至不确定如何调试问题。
这是我的情况:
我已经安装了guzzle
。
我可以从我的服务器通过 cURL
成功发送电子邮件。
在我的 config/services.php
文件中我有:
'mailgun' => [
'domain' => env('MAILGUN_DOMAIN'),
'secret' => env('MAILGUN_SECRET'),
]
我在 .env
文件中设置了:
MAILGUN_DOMAIN=https://api.mailgun.net/v3/sandbox...a.mailgun.org
MAILGUN_SECRET=key-926d...746
在 config/mail.php
中驱动程序默认为 mailgun(我什至在我的 .env
文件中设置了它):
'driver' => env('MAIL_DRIVER', 'mailgun')
我已在 MailGun 中将我的电子邮件验证为授权收件人。
当我在服务器上记录 env 值时,它们就是我在 .env
文件中看到的值。
每次尝试更改时,我都会通过 php artisan config:clear
清除我的配置缓存。
当我在 try/catch
中发送邮件时,我没有收到任何错误。当我检查 Mail::failures();
时,我什么也没得到。
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]);
当我设置 APP_DEBUG=true
和 APP_LOG_LEVEL=debug
时,我的日志中仍然没有任何结果。
根据我的理解,我只需要设置驱动程序、域和密码即可使用 mailguns API(不是通过 smtp)所以我上面的就是我设置的所有内容。
我该怎么做才能找出失败的原因??
.env 文件中的 MAILGUN_DOMAIN 变量应该只是域名(而不是 API url):
而不是
MAILGUN_DOMAIN=https://api.mailgun.net/v3/sandbox...a.mailgun.org
使用
MAILGUN_DOMAIN=sandboxXXXX.mailgun.org