Laravel Mail 发送电子邮件但返回 false
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24772531/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel Mail sending email but returning false
提问by Chris Casper
I am trying to send a email and show any errors if needed. The following code is sending a email and I am receiving it just fine. The issue though, is that when I do the check on the $sent var, it returns false for me.
我正在尝试发送电子邮件并在需要时显示任何错误。下面的代码正在发送一封电子邮件,我收到它就好了。但问题是,当我检查 $sent var 时,它对我返回 false。
Am I just missing something here? It might be because it's late. Who knows...
我只是在这里遗漏了什么吗?可能是因为晚了。谁知道...
$sent = Mail::send('emails.users.reset', compact('user', 'code'), function($m) use ($user)
{
$m->to($user->email)->subject('Activate Your Account');
});
if( ! $sent)
{
$errors = 'Failed to send password reset email, please try again.';
}
回答by judereid
The Mail::send() method doesn't return anything.
Mail::send() 方法不返回任何内容。
You can use the Mail::failures() (introduced in 4.1 I think) method to get an array of failed recipients, in your code it would look something like this.
您可以使用 Mail::failures() (我认为在 4.1 中引入)方法来获取失败收件人的数组,在您的代码中它看起来像这样。
Mail::send('emails.users.reset', compact('user', 'code'), function($m) use ($user)
{
$m->to($user->email)->subject('Activate Your Account');
});
if(count(Mail::failures()) > 0){
$errors = 'Failed to send password reset email, please try again.';
}