How to change From Name in Laravel Mail Notification
In config/mail.php
set from
property as:
'from' => ['address' => 'someemail@somedomain.com', 'name' => 'Firstname Lastname']
Here, address should be the one that you want to display in from email and name should be the one what you want to display in from name.
P.S. This will be a default email setting for each email you send.
EDIT: If you need to use the Name as a variable through code, you can also call the function from() as follows (copying from Brad Ahrens answer below which I think is good to mention here):
return $this ->from($address = 'noreply@domain.com', $name = 'Sender name') ->subject('Here is my subject') ->view('emails.view');
You can use
Mail::send('emails.welcome', $data, function($message) { $message->from('us@example.com', 'Laravel'); $message->to('foo@example.com')->cc('bar@example.com'); });
Reference - https://laravel.com/docs/5.0/mail
A better way would be to add the variable names and values in the .env
file.
Example:
MAIL_DRIVER=smtpMAIL_HOST=smtp.gmail.comMAIL_PORT=587MAIL_USERNAME=example@example.comMAIL_PASSWORD=passwordMAIL_ENCRYPTION=tlsMAIL_FROM_NAME="My Name"MAIL_FROM_ADDRESS=support@example.com
Notice the last two lines. Those will correlate with the from name and from email fields within the Email that is sent.