Reputation: 807
I am sending the email using below code
Mail::send('emails.sample',[],function($message) use($attachment,$filename)
{
$message->subject('PDF is generated !');
$message->from('[email protected]', 'Example');
$message->to('[email protected]');
$message->attachData($attachment,$filename,array('mime'=>'application/pdf','Content-Disposition'=>'attachment'));
});
but after receiving the email, sender email address is coming like this
[email protected] on behalf of Example [email protected]
but it should be like either email address
or name
How do I fix this? any suggestions, please!
Upvotes: 4
Views: 10864
Reputation: 202
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.
Upvotes: 0
Reputation: 12584
you can add these in .env
:
[email protected]
MAIL_FROM_NAME=From Name Surname
in alternative, if you let it blank, you can still change them in config/mail.php
, here replace with yours:
'from' => [
'address' => env('MAIL_FROM_ADDRESS', '[email protected]'),
'name' => env('MAIL_FROM_NAME', 'IDesk'),
],
as you can see config/mail.php
at first try to read it from .env
sto .env
should be used
Upvotes: 4
Reputation: 22395
For anyone still reading this - it's because you need to set the "sender" address. Gmail doesn't seem to care, but Outlook does.
$message->sender(config('mail.from.address'));
Upvotes: 5
Reputation: 929
You'll need to set up some DNS records, so your mail provider can verify that mailgun is allowed to send email on behalf of your domain.
Upvotes: -1
Reputation: 150
Are you using sandbox? Because I am also using the mailgun with sandbox and I am not facing this issue
MAIL_DRIVER=mailgun
MAIL_HOST=smtp.mailgun.org
MAIL_PORT=587
MAIL_USERNAME=postmaster@sandbox3940xxxxxxxxxxxxxxxxxx.mailgun.org
MAIL_PASSWORD=xxxxxxxxxxxxxxxxxxxxxx
MAIL_ENCRYPTION=tls
MAILGUN_DOMAIN=sandboxxxxxxxxxxxxxxxxxxxfaf6.mailgun.org
MAILGUN_SECRET=key-xxxxxxxxxxxxxxxxxxxxxxxxx
Upvotes: -1
Reputation: 256
In config/mail.php
set from property as:
'from' => ['address' => '[email protected]', 'name' => 'Anything you Want']
Upvotes: -1