如何调试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??
我正在尝试使用laravel(5.4)设置mailgun,这对于docs来说听起来很简单,但是 实际工作一直是个噩梦,我甚至不确定如何调试这个问题。 p>
这是我的情况: p>
我有 guzzle code>已安装。 p>
我可以通过 在我的 我在 驱动程序默认使用 我已将我的电子邮件验证为MailGun中的授权收件人。 p>
当我在服务器上记录env值时,它们就是我在 我通过 当我在 当我设置 根据我的理解,我只需要设置驱动程序,域和秘密来使用mailguns API(而不是通过smtp),所以我上面提到的就是我设置的所有内容。 / p>
如何找出失败的原因? p>
div> cURL code>从我的服务器成功发送电子邮件。 p>
config / services.php code>文件中,我有: p>
'mailgun'=&gt; [
'domain'=&gt; env('MAILGUN_DOMAIN'),
'secret'=&gt; env('MAILGUN_SECRET'),
]
code> pre>
.env code>文件中设置了: p> \ ñ
MAILGUN_DOMAIN = HTTPS://api.mailgun.net/v3/sandbox...a.mailgun.org
MAILGUN_SECRET =键-926d ... 746
代码> pre>
config / mail.php code>中的mailgun(我甚至将其设置在我的
.env code>文件中): p>
'driver'=&gt; env('MAIL_DRIVER','mailgun')
code> pre>
.env code>文件中看到的。 p>
每次我尝试更改时都会运行php artisan config:clear code>。 p>
try / catch code>中发送邮件时,我没有收到任何错误 。 当我检查
Mail :: failures(); code>时我什么都没得到。 p>
尝试{
$ mailSent = Mail :: raw('test',function($ message){
$ message-&gt; to('&lt; my authorized) -email&gt;','name');
$ message-&gt; subject('testing');
});
} catch(\ Exception $ e){
dd($ e-&gt; getMessage ());
}
$ fail = Mail :: failures();
if(!empty($ fail))抛出新\ Exception('无法发送消息'。$ fail [0 ]);
code> pre>
APP_DEBUG = true code>和
APP_LOG_LEVEL = debug code>时我仍然得不到任何东西 log。 p>
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