Laravel : How to customize title of email when sending email with Mailable?

Viewed 17097

I write a mailable to send email when user registers,I do it following the document(https://laravel.com/docs/5.5/mail):

first,generating a mailable:

php artisan make:mail UserRegistered

Ok,thus there is a UserRegistered.php file in the app/Mail directory,and I write the build() method like this:

public function build()
{
    return $this->view('emails.activate-user')
                ->with([
                    'name' => $this->user->name,
                    'url' => route('activateUser',['token'=>$this->user->confirmation_token])
                ]);
}

The email can be sent successfully,the title of the email is User Registered,I want to customize the title ,how to do it?

2 Answers

If you want to change mail title you need to change it in .env file. Same Like as given below:

enter image description here

You need to change it here for mail title.

And if you just want to change only subject then you can you use subject() function while sending mail to add you subject.

For Example:

public function build()
{
    return $this->subject('Reset Password')
        ->view('emails.forgotpass');
}

and the final result will be like this where my APP_NAME is Laravel.

Result 1:

enter image description here

Result 2:

enter image description here

Related