How to change reset password email subject in laravel? How to change reset password email subject in laravel? laravel laravel

How to change reset password email subject in laravel?


You can change your password reset email subject, but it will need some extra work. First, you need to create your own implementation of ResetPassword notification.

Create a new notification class insideapp\Notifications directory, let's named it ResetPassword.php:

<?phpnamespace App\Notifications;use Illuminate\Notifications\Notification;use Illuminate\Notifications\Messages\MailMessage;class ResetPassword extends Notification{    public $token;    public function __construct($token)    {        $this->token = $token;    }    public function via($notifiable)    {        return ['mail'];    }    public function toMail($notifiable)    {        return (new MailMessage)            ->subject('Your Reset Password Subject Here')            ->line('You are receiving this email because we received a password reset request for your account.')            ->action('Reset Password', url('password/reset', $this->token))            ->line('If you did not request a password reset, no further action is required.');    }}

You can also generate the notification template using artisan command:

php artisan make:notification ResetPassword

Or you can simply copy-paste the above code. As you may notice this notification class is pretty similar with the default Illuminate\Auth\Notifications\ResetPassword. You can actually just extend it from the default ResetPassword class.

The only difference is here, you add a new method call to define the email's subject:

return (new MailMessage)        ->subject('Your Reset Password Subject Here')

You may read more about Mail Notifications here.

Secondly, on your app\User.php file, you need to override the default sendPasswordResetNotification() method defined by Illuminate\Auth\Passwords\CanResetPassword trait. Now you should use your own ResetPassword implementation:

<?phpnamespace App;use Illuminate\Notifications\Notifiable;use Illuminate\Foundation\Auth\User as Authenticatable;use App\Notifications\ResetPassword as ResetPasswordNotification;class User extends Authenticatable{    use Notifiable;    ...    public function sendPasswordResetNotification($token)    {        // Your your own implementation.        $this->notify(new ResetPasswordNotification($token));    }}

And now your reset password email subject should be updated!

Reset password email subject updated

Hope this help!


You may easily modify the notification class used to send the password reset link to the user. To get started, override the sendPasswordResetNotification method on your User model. Within this method, you may send the notification using any notification class you choose. The password reset $token is the first argument received by the method, See the Doc for Customization

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

Hope this helps!


In Laravel 5.7 the default implementation is similar to this:

return (new MailMessage)            ->subject(Lang::getFromJson('Reset Password Notification'))            ->line(Lang::getFromJson('You are receiving this email because we received a password reset request for your account.'))            ->action(Lang::getFromJson('Reset Password'), url(config('app.url').route('password.reset', $this->token, false)))            ->line(Lang::getFromJson('This password reset link will expire in :count minutes.', ['count' => config('auth.passwords.users.expire')]))            ->line(Lang::getFromJson('If you did not request a password reset, no further action is required.'));

All you have to do is change your locale from config/app.php for example to ro, then in your resources/lang, create a file ro.json similar to this:

{  "Reset Password Notification": "Viața Medicală CMS :: Resetare parolă",  "Hello!": "Salut,",  "You are receiving this email because we received a password reset request for your account.": "Primești acest email deoarece am primit o solicitare de resetare a parolei pentru contul tău.",  "Reset Password": "Reseteză parola",  "This password reset link will expire in :count minutes.": "Acest link va expira în :count de minute.",  "If you did not request a password reset, no further action is required.": "Dacă nu ai solicitat resetarea parolei, nu este necesară nicio altă acțiune.",  "Regards": "Toate cele bune",  "Oh no": "O, nu",  "Whoops!": "Hopa!",  "If you’re having trouble clicking the \":actionText\" button, copy and paste the URL below\ninto your web browser: [:actionURL](:actionURL)": "Dacă nu reușești să dai click pe butonul de \":actionText\", dă copy-paste la URL-ul de mai jos în browser:\n [:actionURL](:actionURL)"}

It will translate both the subject (first key) and the mail body.

UPDATE for Laravel 6.*
This can be also used for VerifyEmail.php notification.