11
votes

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?

1

1 Answers

31
votes

You have to use subject method

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

Or update your mails class's constructor

public function __construct()
    {

        $this->subject('Sample title');
    }