Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

rawfan's avatar
Level 19

How to customize password resets using toMailUsing

Hi,

the usual way of customizing this would be to create your own notification and use it by overriding the sendPasswordResetNotification-Method on your User model (see here).

Now Taylor added a toMailUsing()-method to the ResetPassword notification and recommended using it instead of creating a new notification. I just have no idea how to do that. My current approach is something like this, but it doesn't work:

public function sendPasswordResetNotification($token)
{
    $notification = new ResetPasswordNotification($token);
    $notification->toMailUsing(function () use ($token) {
        return (new MailMessage)
            ->line('You are receiving this email because we received a password reset request for your account.')
            ->action('Reset Password', url(config('app.url').route('password.reset', $token, false)))
            ->line('If you did not request a password reset, no further action is required.');
    });

    $this->notify($notification);
}

Any ideas?

0 likes
5 replies
rawfan's avatar
Level 19

Solved my own problem. The exact code above does actually work. ;-)

patrickcarlohickman's avatar

The toMailUsing() method is static, so I'm assuming the intention was to use the static method in a service provider or something, so that you wouldn't have to override the sendPasswordResetNotification() method on your user.

So, for example, in your AppServiceProvider boot() method, you would have something like:

\Illuminate\Auth\Notifications\ResetPassword::toMailUsing(function ($notifiable, $token) {
    return (new \Illuminate\Notifications\Messages\MailMessage)
        ->line('You are receiving this email because we received a password reset request for your account.')
        ->action('Reset Password', url(config('app.url').route('password.reset', $token, false)))
        ->line('If you did not request a password reset, no further action is required.');
});
4 likes
rawfan's avatar
Level 19

@patrickcarlohickman Hm, I'm quite sure I tried that. I'll try again, thank you! If it works it would really help me with a package right now that I wouldn't be able to do otherwise! Stay tuned for the release. ;)

omidwolf's avatar

my problem is: i cant remove or change first line ("Hello!") and last line ("if you having trouble ...") in email verification text how can i do this?

Please or to participate in this conversation.