简体   繁体   English

只能使用Laravel 5和Mailgun向自己发送电子邮件

[英]Can only send email to myself using Laravel 5 and Mailgun

I've been able to successfully send an email to myself using a combination of Laravel 5 and Mailgun but I am getting a frustrating "bad request" error when I try to change just one line of the code. 我已经能够结合使用Laravel 5和Mailgun成功地向自己发送电子邮件,但是当我尝试仅更改一行代码时,却遇到了令人沮丧的“错误请求”错误。 Specifically, when I change this line: 具体来说,当我更改此行时:

$message->to('xxx@mydomain.com') to an email that is not the one used by my Mailgun account, I get a bad request error. $ message-> to('xxx@mydomain.com')发送到不是我的Mailgun帐户使用的电子邮件,我收到了错误的请求错误。 That is the only thing I am changing. 那是我唯一要改变的事情。

Edit (here is my code): 编辑(这是我的代码):

Mail::send('emails.alerts.assess_tomorrow', $view_data, function($message) {
$message->to('xxx@mydomain.com')->subject('test 23')->from('xxx@mydomain.com');
            });

Edit2 (my mail.php code): Edit2(我的mail.php代码):

<?php

return [

        'driver' => 'mailgun',
        'host' => 'smtp.mailgun.org',
        'port' => 587,
        'from' => ['address' => 'xxx@mydomain.com', 'name' => 'A Name'],
    'encryption' => 'tls',
        'username' => 'my mailgun postmaster username',
        'password' => 'my mailgun password',
    'sendmail' => '/usr/sbin/sendmail -bs',
    'pretend' => false,

];

I have installed Guzzle and updated laravel. 我已经安装了Guzzle并更新了laravel。 As I mentioned, this works perfectly when the "to" email is to myself (the address used by my mailgun account). 正如我提到的,当“收件人”电子邮件是给我自己(我的mailgun帐户使用的地址)时,此方法非常有效。

In other words, I can only send an email to myself. 换句话说,我只能向自己发送电子邮件。 So I know the code is basically working, but it seems changing the "to" address (for example to my gmail address), results in the bad request error. 所以我知道代码基本上可以正常工作,但是似乎将“到”地址(例如更改为我的gmail地址)更改会导致错误的请求错误。

Am I missing something obvious? 我是否缺少明显的东西? Many thanks for any ideas! 非常感谢您的任何想法!

SOLVED! 解决了! What a maroon I am. 我真是个栗色。 I didn't notice that my mailgun account needed to be verified before I could send an email to other addresses. 我没有注意到我的mailgun帐户需要先经过验证,然后才能将电子邮件发送到其他地址。

I logged into mailgun and resent the activation email. 我登录到mailgun并重新发送了激活电子邮件。 After the account was activated, everything worked perfectly. 激活帐户后,一切正常。 Sorry to take up your time but perhaps this might help other wayward folks! 抱歉,占用您的时间,但这也许对其他任性的人有所帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM