Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

laravel-5

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?

like image 302
zwl1619 Avatar asked Sep 15 '17 18:09

zwl1619


1 Answers

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');
    }
like image 73
Suresh Velusamy Avatar answered Oct 20 '22 04:10

Suresh Velusamy