如何调试laravel mailgun

我正在尝试使用laravel(5.4)设置mailgun,这对于docs来说听起来很简单,但是 实际工作一直是个噩梦,我甚至不确定如何调试这个问题。</ p>

这是我的情况:</ p>

我有< 代码> guzzle </ code>已安装。</ p>

我可以通过 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>

我已将我的电子邮件验证为MailGun中的授权收件人。</ p>

当我在服务器上记录env值时,它们就是我在 .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>

根据我的理解,我只需要设置驱动程序,域和秘密来使用mailguns API(而不是通过smtp),所以我上面提到的就是我设置的所有内容。 / p>

如何找出失败的原因?</ p>
</ div>

展开原文

原文

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个回答



.env文件中的MAILGUN_DOMAIN变量应该只是域名(而不是API网址):</ p>

而不是</ p>

  MAILGUN_DOMAIN = https://api.mailgun.net/v3/sandbox...a.mailgun.org 
</ code> </ pre>

使用</ p>

  MAILGUN_DOMAIN = sandboxXXXX.mailgun.org 
</ code> </ pre>
</ div>

展开原文

原文

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

dongmibeng5885
dongmibeng5885 天啊......我应该注意到......谢谢!
3 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐