replace password reset mail template with custom template laravel 5.3
Just a heads up: In addition to the previous answer, there are additional steps if you want to modify the notification lines like You are receiving this...
, etc. Below is a step-by-step guide.
You'll need to override the default sendPasswordResetNotification
method on your User
model.
Why? Because the lines are pulled from Illuminate\Auth\Notifications\ResetPassword.php
. Modifying it in the core will mean your changes are lost during an update of Laravel.
To do this, add the following to your your User
model.
use App\Notifications\PasswordReset; // Or the location that you store your notifications (this is default).
/**
* Send the password reset notification.
*
* @param string $token
* @return void
*/
public function sendPasswordResetNotification($token)
{
$this->notify(new PasswordReset($token));
}
Lastly, create that notification:
php artisan make:notification PasswordReset
And example of this notification's content:
/**
* The password reset token.
*
* @var string
*/
public $token;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct($token)
{
$this->token = $token;
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['mail'];
}
/**
* Build the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
return (new MailMessage)
->line('You are receiving this email because we received a password reset request for your account.') // Here are the lines you can safely override
->action('Reset Password', url('password/reset', $this->token))
->line('If you did not request a password reset, no further action is required.');
}
Run the following command in the terminal and the two email templates will be copied to your resources/vendor/notifications folder. Then you can modify the templates.
php artisan vendor:publish --tag=laravel-notifications
You can read more about Notifications
in Laravel Docs.