Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing the default “Subject” field for verification emails in Laravel 5.7

I'm trying to change the default subject field in the verification email that comes with Laravel 5.7. How and where do I change it? I have searched all over the place and online. Because it's brand new I can't find an answer.

like image 942
GabMic Avatar asked Sep 19 '18 14:09

GabMic


People also ask

How do I change the subject in Laravel mail?

Laravel provides subject() where we can change the subject of the email. We will change the following code on MyTestMail class as follows and you will see how to change from name and address with output. Read Also: How to Send Email to Multiple Users in Laravel? * Create a new message instance.


1 Answers

You don't need to code anything. The notification has all the strings wrapped in the Lang class so that you can provide translation strings from english to another language, or even english to english if you just want to change the wording.

Look in /vendor/laravel/framework/src/Illuminate/Auth/Notifications/VerifyEmail.php

public function toMail($notifiable)
{
    if (static::$toMailCallback) {
        return call_user_func(static::$toMailCallback, $notifiable);
    }

    return (new MailMessage)
        ->subject(Lang::getFromJson('Verify Email Address'))
        ->line(Lang::getFromJson('Please click the button below to verify your email address.'))
        ->action(
            Lang::getFromJson('Verify Email Address'),
            $this->verificationUrl($notifiable)
        )
        ->line(Lang::getFromJson('If you did not create an account, no further action is required.'));
}

You can see all the strings there.

Create a file en.json if you don't have one on the resources/lang folder already.

add the original string and the replacement. eg

{
    "Verify Email Address": "My preferred subject",
    "Please click the button below to verify your email address.":"Another translation"
}

To translate to another language, change the locale in config/app.php and create a translation file with the locale.json

like image 67
Snapey Avatar answered Sep 23 '22 00:09

Snapey