Laravel how to configure sender name instead of email address

Viewed 10485

How do I configure the sender name in the .env or mail.php files in Laravel? I set the email configuration in both of these files as below.

.env:

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=jayabahadurgmail.com
MAIL_PASSWORD=9491A$$R
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS = noreply@email.com
MAIL_FROM_NAME = NO-REPLY

config/mail.php file:

'from' => [
    'address' => 'sender@gmail.com',
    'name' => 'NONAME'
],

The issue is that when I receive an email, it shows my email address like "jayabahadurgmail.com", but I want to show "NO-REPLY" instead of my email.

2 Answers

Gmail automatically rewrites the "from" header of any messages sent through its SMTP server to the default "Send mail as" email address assigned in the Gmail or Google Apps account used to authenticate (in this case, your personal account).

This SMTP service is intended for personal use only, so its not very flexible. We can change this address by modifying the default account in the Gmail settings, but this still won't enable us to configure the "from" address through the application.

In development, this behavior may not matter, but for production environments, we'd need to use a mail provider that respects the headers sent from the application. Gmail also limits the rate of emails sent through its SMTP server in this way, which prevents us from using the service for most applications in production that send any significant amount of email.

just go to mail.php and edit

'from' => [
    'address' => env('MAIL_FROM_ADDRESS', 'no-reply@bepunct.com'),
    'name' => env('MAIL_FROM_NAME', 'BePunct'),
],

save. That's all. Make sure you config:clear to load the .env

Tested with Mailgun and Mailtrap.. Gmail i think it is not supported yet..

If you are using queue.. restart the queue.. and try it again

Related