Laravel - How to Set Subject in Mail?
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...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to Change From Name in Laravel Mail?
- Laravel Send Email with Multiple Attachment Example
- Laravel Two Factor Authentication using Email Tutorial
- How to Send Mail using Sendinblue in Laravel?
- How to Send Mail using Mailjet in Laravel?
- Laravel Send Mail using Mailgun Example
- Laravel 8 Mailgun Integration Example
- How to Send Email with Attachment in Laravel?
- Laravel Send Mail using Mailtrap Example
- Laravel 8 Send Mail using Gmail SMTP Server