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 = 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.';
}

推荐答案

The Mail::send() method doesn't return anything.

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::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.';
}

Laravel相关问答推荐

灯丝:设定模式标题

无法在终端cPanel中打开输入文件:artisan

Laravel 数据未传递到下拉框

Laravel 9 上的数组差异助手

错误try 访问 null 类型值的数组偏移量laravel 5.8.26 Php 7.4.2

我的composer 不会完全用 Laravel 4 更新它会被artisan卡住

如何在 laravel 中使用 str_replace

刚安装 Lumen 并得到 NotFoundHttpException

在 VSCode 上调试 Laravel 应用程序

Laravel 说 Auth guard [] 没有定义

禁用Eager的关系

Laravel 无法创建根目录

Laravel 迁移命名约定

如何从 Laravel 中的资源中获取图像?

Select,where JSON 包含数组

Laravel 隐藏属性.例如密码 - 安全

控制器中的artisan调用输出?

无法在控制器的构造函数上调用 Auth::user()

Laravel 集合计数结果

如何在 laravel 表单验证错误消息中给出自定义字段名称