Laravel邮件队列密码重置

时间:2016-09-15 17:46:51

标签: php laravel laravel-5.2

我正试图在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,则可以正常使用。我无法想象你发生了什么。

2 个答案:

答案 0 :(得分:0)

当您将某些内容放入队列时,Laravel将其序列化为纯文本,并将其存储到数据库中 - 它无法通过对象执行此操作。

相反:创建一个Job,它捕获发送电子邮件所需的所有信息(用户,令牌等),然后在调用作业时,像往常一样调用mail函数。

答案 1 :(得分:0)

您需要将用户电子邮件ID声明为变量,然后将其传递给邮件功能

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);
            }
        });
    }