How to Change From Name in Laravel Mail?

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 and laravel 8 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 AppMail;

use IlluminateBusQueueable;

use IlluminateContractsQueueShouldQueue;

use IlluminateMailMailable;

use IlluminateQueueSerializesModels;

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:

How to Change From Name in Laravel Mail?

I hope it can help you…

Leave a Comment