[英]Laravel Mail queue Password Reset
I'am trying to queue the password reset mail on laravel. 我正在尝试在laravel上排队密码重置邮件。
I have tried cloning the PasswordBroker as follow: 我尝试按以下方式克隆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);
}
});
}
}
Then I get this error: 然后我得到这个错误:
exception 'ErrorException' with message 'Serialization of closure failed: Serialization of closure failed: Serialization of 'Closure' is not allowed'
If I change mailer->queue
to mailer->send
it works fine. 如果我将
mailer->queue
更改为mailer->send
它可以正常工作。 I can't figure ou what is happening. 我不知道发生了什么事。
When you put something into the Queue, Laravel serializes it into plain text, and stores it into the database - it can't do this with objects. 当您将某些内容放入Queue时,Laravel会将其序列化为纯文本,并将其存储到数据库中-它无法使用对象来完成此操作。
Instead: create a Job that captures all the info you need to send the email (user, token, etc), and then when the job is called, call the mail function as usual. 而是:创建一个作业,以捕获您发送电子邮件所需的所有信息(用户,令牌等),然后在调用该作业时,照常调用mail函数。
You need to declare the user email id to a variable and then pass it to the mail function 您需要将用户电子邮件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.