Kalim
Kalim

Reputation: 499

Mail does not override from email address in Laravel 5.2?

I am sending email using Gmail SMTP account, but I want show different sender email to the receiver. I am using below code to override the from email address.

Mail::send('emails_old.send_message', ['data' => $request->message], function ($message) use ($request, $toEmail, $cc, $bcc, $attacments)
  {
    $message->to($toEmail);
    $message->subject($request->subject);
    $message->from('no-reply@xyz', 'No reply');
    $message->replyTo(auth()->user()->email, auth()->user()->name);
  });

Above code working fine & also overrides sender name, but not email address.

can anybody tells what's wrong I am doing?

Thanks, Kaleem

Upvotes: 0

Views: 979

Answers (1)

Rick J
Rick J

Reputation: 166

Gmail only permits you to use a From address that's in your Settings as a verified alias. You can't (and shouldn't) spoof an email address you don't control. If nothing else, it'll frequently be flagged as spam because of SPF records. – ceejayoz

If you want to use a different email address where the mail is send from try using a mail server, or try using a maildriver such as mailgun.

I only use Gmail SMTP for development, after that I switch over to my mail server.

I'd note that while other services may allow you to do this, it's still a horrible idea. SPF records will send a lot of email sent like this to spam. – ceejayoz

So if it's just for development or a school-project, you can use mailservices like mailgun or Gmail SMTP. Otherwise try to get a mail server to handle no-reply emails.

Upvotes: 4

Related Questions