ItSolutionStuff.com

Laravel - How to Set Subject in Mail?

By Hardik Savani • April 16, 2024
Laravel

Hi Dev,

Now, let's see a tutorial of laravel mail change subject. if you want to see an example of laravel mail set subject then you are the right place. I would like to show you how to set subject in email laravel. you can understand a concept of set subject in laravel mail. Let's see below the example laravel set subject mail.

If you want to change the subject then I will let you know how to set the subject in laravel mail. you can use this example with laravel 6, laravel 7, laravel 8, laravel 9, laravel 10 and laravel 11 version.

Yesterday, i write following tutorial about send email with multiple attachment, you can follow this tutorial here: Laravel Send Email with Multiple Attachment Example.

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.

Solution:

public function build()

{

return $this->view('emails.myTestMail')

->subject('Your Subject Here');

}

let's see MyTestMail.php file code as like bellow:

app/Mail/MyTestMail.php

<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Mail\Mailable;

use Illuminate\Queue\SerializesModels;

class MyTestMail extends Mailable

{

use Queueable, SerializesModels;

public $details;

/**

* Create a new message instance.

*

* @return void

*/

public function __construct($details)

{

$this->details = $details;

}

/**

* Build the message.

*

* @return $this

*/

public function build()

{

$this->subject('Mail from ItSolutionStuff.com')

->view('emails.myTestMail');

return $this;

}

}

Output:

I hope it can help you...

Tags: Laravel
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

How to Change From Name in Laravel Mail?

Read Now →

Laravel Send Email with Multiple Attachment Example

Read Now →

Laravel Two Factor Authentication using Email Tutorial

Read Now →

How to Send Mail using Sendinblue in Laravel?

Read Now →

How to Send Mail using Mailjet in Laravel?

Read Now →

Laravel Send Mail using Mailgun Example

Read Now →

Laravel 8 Mailgun Integration Example

Read Now →

How to Send Email with Attachment in Laravel?

Read Now →

Laravel Send Mail using Mailtrap Example

Read Now →

Laravel 8 Send Mail using Gmail SMTP Server

Read Now →