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

Laraveldeep's avatar

[Laravel 5.3.6] How To Replace Password Reset Mail with Custom Mailable Template?

Hi,

I am using Laravel 5.3.6 and using the out of the box user authentication using "make:auth".

My question: How to replace default password reset mail template with custom created Mailable template?

I thought of overriding the method in "Illuminate\Foundation\Auth\SendsPasswordResetEmails" in my "ForgotPasswordController.php"

    public function sendResetLinkEmail(Request $request)
    {
        $this->validate($request, ['email' => 'required|email']);

        // We will send the password reset link to this user. Once we have attempted
        // to send the link, we will examine the response then see the message we
        // need to show to the user. Finally, we'll send out a proper response.
        $response = $this->broker()->sendResetLink(
            $request->only('email'), $this->resetNotifier()
        );

        if ($response === Password::RESET_LINK_SENT) {
            return back()->with('status', trans($response));
        }

        // If an error was returned by the password broker, we will get this message
        // translated so we can notify a user of the problem. We'll redirect back
        // to where the users came from so they can attempt this process again.
        return back()->withErrors(
            ['email' => trans($response)]
        );
    }

But it is deeply linked with other traits, brokers, which validates and checks for common errors and db look up already.

If I am to override this method,I have to bypass all these goodies and implement my own validations.

Any suggestion on how to just replace the custom mail template with default one? I am not sure how that mail template is generated. Its not under any view.

Thanks!

0 likes
7 replies
hxd's avatar

you can change 2 files to change password reset email template

path: \vendor\laravel\framework\src\Illuminate\Auth\Notifications\ResetPassword.php ,functin toMail() ,you can edit email's title, password reset url, and button's content。

path2: \vendor\laravel\framework\src\Illuminate\Notifications\resources\views\email.blade.php , It's the view of password reset email template, like others blades.

Laraveldeep's avatar

@XiaodongHe : Thanks for to the point answer. That's what exactly I wanted to know.

After looking at it, I am thinking of overriding the "toMail()" method to send my custom mail but I have new questions

  1. What is MailMessage returned by "toMail()" method and where its been interpreted?

I don't fully understand what's going on yet but my guess is that its just composing the mail from provided strings.

If I were to override the "toMail()" with my Mailable mail like this:

Mail::to($request->email)->send(new PasswordResetMail($passwordresetlink));

Will this bypass security checks along the way?

  1. ResetPassword is not a trait, so how do we override its methods?

Thanks!

hxd's avatar

@Laraveldeep I think you can override this method, it seems function toMail() just send a reset password email with the reset url, and edit it like this : return Mail::to($request->email)->send(new PasswordResetMail($passwordresetlink));

i don't attempt to modify it, hope someone attempt can answer this question.

Laraveldeep's avatar

Thanks @XiaodongHe

I have tried to override this method but its not executing. Instead flow still follows the core method and sends old template.

As I mentioned earlier "ResetPassword .php" is a class not trait. I am still checking.

By the way my requirement is for branding purpose. I have successfully added the email verification system when user signs up . I wanted that all the authentication mail like email verification, password reset etc follow the same branding template.

I will revisit this when I am done with other parts of the project.

Thanks for your time.

Laraveldeep's avatar
Laraveldeep
OP
Best Answer
Level 7

This lessen gave me some hints.

https://laracasts.com/series/whats-new-in-laravel-5-3/episodes/9

I think I will be switiching to 'Notifications' for all user account related mail system.

Basically I can just do this:

php artisan vendor:publish

This will publish the

\vendor\laravel\framework\src\Illuminate\Notifications\resources\views
To 
\resources\views\vendor\notifications
.
.
.
plus pagination

At this point I can just customize the email template to my branding needs.

In my case I have extra feature to verify user account after they register, so I can use the Notification:Email channel to send that mail.

May be for other mailing needs I can use the Mailable (like newsletters etc.)

12 likes
mikkolauhakari's avatar

Hey guys.

I'm not sure if you @HeXiaodong meant that he should change the files inside the \vendor\laravel\framework.... folder, but generally you should never change files inside the /vendor/... folder. Especially for customisation purposes. For one if you update your package your changes will be gone.

Just my two cents on that.

I'm about to change my password reset emails too and found this in the docs at the bottom of the password page: "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"

3 likes

Please or to participate in this conversation.