Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use MAIL_FROM_ADDRESS?

Currently, I'm working on a feature that requires the application to send emails to customers/users.

Sending emails is already working, however, I want the sender's email to be hidden/replaced. I thought that the MAIL_FROM_ADDRESS in .env file is what I needed, but it didn't give me what I expected.

Here's a snippet from my .env file:

# illuminate/mail
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=PASSWORD_HERE
[email protected]
MAIL_FROM_NAME=MyApp

Should the user receive an email coming from my app, it should display "[email protected]" as the sender of the email.

+------+

Why is MAIL_FROM_ADDRESS not working?

How should I use it?

Am I wrong to think that it is the solution to my problem?

What should I do to achieve the expected output?

like image 312
Steven Avatar asked Sep 06 '17 07:09

Steven


1 Answers

You can't replace sender with Google SMTP service.

Google rewrites the From and Reply-To headers in messages you send via it's SMTP service to values which relate to your gmail account.

GMail does allow sending via different addresses or alias but this is for sending via the GMail web app.

Solution: If you own the domain you are supposedly sending from, use the gmail for domains, and setup a "[email protected]" account.

like image 128
TuanTai Avatar answered Nov 05 '22 17:11

TuanTai