[英]Laravel Mail queue Password Reset
我正在尝试在laravel上排队密码重置邮件。
我尝试按以下方式克隆PasswordBroker:
<?php
namespace App;
use Closure;
use Illuminate\Auth\Passwords\PasswordBroker as IlluminatePasswordBroker;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
class PasswordBroker extends IlluminatePasswordBroker
{
public function emailResetLink(CanResetPasswordContract $user, $token, Closure $callback = null)
{
// We will use the reminder view that was given to the broker to display the
// password reminder e-mail. We'll pass a "token" variable into the views
// so that it may be displayed for an user to click for password reset.
$view = $this->emailView;
return $this->mailer->queue($view, compact('token', 'user'), function ($m) use ($user, $token, $callback) {
$m->to($user->getEmailForPasswordReset());
if (! is_null($callback)) {
call_user_func($callback, $m, $user, $token);
}
});
}
}
然后我得到这个错误:
exception 'ErrorException' with message 'Serialization of closure failed: Serialization of closure failed: Serialization of 'Closure' is not allowed'
如果我将mailer->queue
更改为mailer->send
它可以正常工作。 我不知道发生了什么事。
当您将某些内容放入Queue时,Laravel会将其序列化为纯文本,并将其存储到数据库中-它无法使用对象来完成此操作。
而是:创建一个作业,以捕获您发送电子邮件所需的所有信息(用户,令牌等),然后在调用该作业时,照常调用mail函数。
您需要将用户电子邮件ID声明为一个变量,然后将其传递给mail函数。
public function emailResetLink(CanResetPasswordContract $user, $token, Closure $callback = null)
{
$view = $this->emailView;
$to = $user->getEmailForPasswordReset();
return $this->mailer->queue($view, compact('token', 'user'), function ($m) use ($user,$to, $token, $callback) {
$m->to($to);
if (! is_null($callback)) {
call_user_func($callback, $m, $user, $token);
}
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.