pstephan1187's avatar

Reset Password Email Subject

When the password broker sends the reset password email, the email does not have a subject. If you look into the Password Broker class, you will see that a subject is not even set:

    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->send($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);
        });
    }

Is there a way to set a subject for the email without overwriting the Password Broker? I have tried making the email view an HTML instead of text view and adding a <title> tag, but that didn't seem to help? Any ideas?

0 likes
5 replies
pstephan1187's avatar
pstephan1187
OP
Best Answer
Level 7

I submitted this 2 minutes too early. I figured it out. The sendResetLink() method in the PasswordBroker accepts a callback which is eventually passed to the mailer function that sends the password reset email. The first argument of the closure is the mailer object. So you can simply do something like this:

$this->passwords->sendResetLink($request->only('email'), function($mailer){
    $mailer->subject('Reset Password Subject');
});

xingfucoder's avatar

Hi @pstephan1187, if I'm not wrong, a default subject was added some time ago to the Password remainder.

What version of Laravel are you using?

xingfucoder's avatar

Sorry @pstephan1187 it was the ResetPassword trait, here you can find I think you are searching:

https://github.com/laravel/framework/blob/5.0/src/Illuminate/Foundation/Auth/ResetsPasswords.php#L46

And the getEmailSubject method with a default subject value that use the subject propertie.

https://github.com/laravel/framework/blob/5.0/src/Illuminate/Foundation/Auth/ResetsPasswords.php#L64

This trait is used by the PasswordController then I think, you may change the subject property.

Please or to participate in this conversation.