0

I am sending mail with laravel. Mail is in gmail but from and to address is same in gmail why ? i am confused. env

MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=abc2020
MAIL_PASSWORD=Abc@123
MAIL_ENCRYPTION=tls



             \Mail::send('invoice', array(
                                'name' => $user_details->name,
                                'email' => $user_details->email,
                                'subject' =>'Order is placed',
                            ), function($message) use ($req){
                                $message->from($req->email,'Order');
                                $message->to('abc2020@gmail.com')->subject('Order is Placed');
                            });

Invoic is send in email but from address is same as to address

from:abc2020@gmail.com to:abc2020@gmail.com

What is changes in code so that from address is from $req->email..

  • Please check what is the value you are getting in your `$req` object. It might be the case that your `$req->email` is getting same email as your `abc2020@gmail.com`. Or try to change your `MAIL_USERNAME` value from .env and run `php artisan config:clear` – Jayant Apr 06 '21 at 08:57
  • Does this answer your question? [How to change from-address when using gmail smtp server](https://stackoverflow.com/questions/1332510/how-to-change-from-address-when-using-gmail-smtp-server) – P. K. Tharindu Apr 06 '21 at 09:00

1 Answers1

0

Google rewrites the From and Reply-To headers in messages you send via its SMTP service to values that relate to your Gmail account. So changing it in the codebase will make no difference.

If you need to modify the From and/or Reply-To addresses, you need to consider alternative SMTP services.

P. K. Tharindu
  • 2,565
  • 3
  • 17
  • 34