Replace password reset email in Laravel 5.6
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
Copied!
1<?php 2 3namespace App\Notifications; 4 5use Illuminate\Auth\Notifications\ResetPassword; 6use Illuminate\Notifications\Messages\MailMessage; 7 8class ResetPasswordNotification extends ResetPassword 9{10 /**11 * Build the mail representation of the notification.12 *13 * @param mixed $notifiable14 * @return \Illuminate\Notifications\Messages\MailMessage15 */16 public function toMail($notifiable)17 {18 if (static::$toMailCallback) {19 return call_user_func(static::$toMailCallback, $notifiable, $this->token);20 }21 22 return (new MailMessage)23 ->line('You are receiving this email because we received a password reset request for your account.')24 ->action('Reset Password', url(config('app.url').route('password.reset', $this->token, false)))25 ->line('If you did not request a password reset, no further action is required.');26 }27}
Edit App/User.php
add at the top
Copied!
1use App\Notifications\ResetPasswordNotification;
and add the following method
Copied!
1/** 2 * Send the password reset notification. 3 * @note: This override Authenticatable methodology 4 * 5 * @param string $token 6 * @return void 7 */ 8public function sendPasswordResetNotification($token) 9{10 $this->notify(new ResetPasswordNotification($token));11}
If you want to edit the HTML of the email and not the contents, you would run:
Copied!
1php 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.