Jose Jimenez
Software Architect & Developer
> >

Replace password reset email in Laravel 5.6

Published in Laravel, PHP on Mar 11, 2018

I saw a few posts from people asking how to change the default reset password email contents in Laravel 5.6. This method will simply overwrite one method in Authenticatable.

Create file Notifications/ResetPasswordNotification.php

<?php

namespace App\Notifications;

use Illuminate\Auth\Notifications\ResetPassword;
use Illuminate\Notifications\Messages\MailMessage;

class ResetPasswordNotification extends ResetPassword
{
    /**
     * Build the mail representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return \Illuminate\Notifications\Messages\MailMessage
     */
    public function toMail($notifiable)
    {
        if (static::$toMailCallback) {
            return call_user_func(static::$toMailCallback, $notifiable, $this->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', $this->token, false)))
            ->line('If you did not request a password reset, no further action is required.');
    }
}

Edit App/User.php add at the top

use App\Notifications\ResetPasswordNotification;

and add the following method

    /**
     * Send the password reset notification.
     * @note: This override Authenticatable methodology
     *
     * @param  string  $token
     * @return void
     */
    public function sendPasswordResetNotification($token)
    {
        $this->notify(new ResetPasswordNotification($token));
    }

If you want to edit the HTML of the email and not the contents, you would run:

php artisan vendor:publish --tag=laravel-notifications

It will create the following file that you can edit resources/views/vendor/notifications/email.blade.php but be careful since it will affect email templates in general.