How to Customize Password Recovery Email (Laravel 5.4)

Asked

Viewed 6,007 times

7

As I can customize the Laravel 5.4 password recovery email, I need to change the language but can’t find the place to edit.

3 answers

11

Step-by-step instruction:

You must create a new notification class to override the default text of the message.

  1. To create a new notification class you must use this command line:

    php artisan make:notification meuResetDeSenha
    

This will create the new class 'myResetDelf' in the app/Notifications directory.

  1. Change the generated file constructor to:

    public function __construct($token)
    {
        $this->token = $token;
    }
    
  2. Add the following import to the user model (probably in app/User.php):

    use App\Notifications\meuResetDeSenha;
    
  3. Add this new method to the user model:

    public function sendPasswordResetNotification($token)
    {
        $this->notify(new meuResetDeSenha($token));
    }
    
  4. Run the following Artisan command to publish the changes.

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

After running this command, the notification email template will be located in the Resources/views/vendor/Notifications directory

  1. Edit the text in line and action of the toMail() method in your myResetDelf class

    public function toMail($notifiable)
    {
        return (new MailMessage)
            ->subject('Assunto do email')
            ->greeting('Olá!')
            ->line('Você está recebendo este e-mail porque nós recebemos uma requisição para sua conta.')
            ->action('REDEFINIR SENHA', route('password.reset', $this->token))
            ->line('Se você não requisitou uma redefiniçã de senha, nenhuma ação é necessária.')
            ->markdown('vendor.notifications.email');
    }
    

This is described in https://laravel.com/docs/5.4/notifications#formatting-mail-messages

  1. Edit email text in Resources/views/vendor/Notifications/email.blade.php if you want.

Although most of it is translated from https://stackoverflow.com/questions/39327954/laravel-5-3-redefine-reset-email-blade-template , I added step 2 in my reply, as I needed to implement it to work here and added markdown in step 6.

  • Need to do something else, does not send the email gives Failed to load Resource: the server responded with a status of 500 (Internal Server Error)... Have somewhere other than . env to include email settings.. type smtp, port. etc... Obs. I am already sending emails in another view set up in . env...

  • It even has in /config/mail.php, but I don’t know if it’s there what you need.

1

the translation files are in the Resource/lang/ folder the file referring to the login areas is auth.php you can edit it as you like.

  • I have already changed these files, they serve only for the validation of the fields, what I need is to edit the password recovery email that the Standard sends.

0

I think that’s the file:

Resources/views/vendor/Notifications/email.blade.php

Browser other questions tagged

You are not signed in. Login or sign up in order to post.