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, 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...
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
- 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?
- How to Generate PDF and Send Email in Laravel?
- How to Send Mail in Laravel 8 using Mailtrap?
- Laravel Send Mail using Mailtrap Example
- Laravel 8 Send Mail using Queue Example
- Laravel Mailgun Setup Example