How to Change From Name in Laravel Mail?

By Hardik Savani April 16, 2024 Category : Laravel

Hi Dev,

In this post, we will learn laravel mail change from the name. I explained simply about how to change from name in laravel mail. This post will give you a simple example of laravel mail change from address. This article will give you a simple example of laravel change from name in email.

If you want to change from name and from address then i will let you know how to change from name and from email 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 from() where we can change email and name of mail.

We will change the following code on MyTestMail class as follows and you will see how to change from name and address with output.

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()

{

$address = config("mail.from.address");

$name = 'My Project';

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

->view('emails.myTestMail')

->from($address, $name);

return $this;

}

}

Output:

I hope it can help you...

Tags :
Shares