3

I am sending the email using below code

Mail::send('emails.sample',[],function($message) use($attachment,$filename)
        {
            $message->subject('PDF is generated !');
            $message->from('test@example.com', 'Example');
            $message->to('user@gmail.com');
            $message->attachData($attachment,$filename,array('mime'=>'application/pdf','Content-Disposition'=>'attachment'));
        });

but after receiving the email, sender email address is coming like this

test=example.com@mailgun.org on behalf of Example test@example.com

but it should be like either email address or name

test@example.com

How do I fix this? any suggestions, please!

06011991
  • 797
  • 2
  • 13
  • 39

6 Answers6

4

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'));
Gary Green
  • 22,045
  • 6
  • 49
  • 75
3

you can add these in .env:

MAIL_FROM_ADDRESS=from@domain.com
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', 'info@idesk.com'),
    '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

Luca C.
  • 11,714
  • 1
  • 86
  • 77
0

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.

Hamza Qureshi
  • 172
  • 2
  • 20
-1

In config/mail.php

set from property as:

'from' => ['address' => 'test@example.com', 'name' => 'Anything you Want']
Masud Miah
  • 236
  • 1
  • 4
-1

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
Kevin Patel
  • 152
  • 6
  • The above code is from .env and you have to use this info in config/mail.php – Kevin Patel Jul 31 '17 at 13:06
  • even I have setup the same way, but I don't know why it's not working for me? – 06011991 Jul 31 '17 at 13:11
  • Share your `config/mail.php` – Kevin Patel Jul 31 '17 at 13:13
  • `return [ 'driver' => env('MAIL_DRIVER', 'smtp'), 'host' => env('MAIL_HOST', 'smtp.mailgun.org'), 'port' => env('MAIL_PORT', 587), 'from' => [ 'address' => 'test@example.com', 'name' => 'Example', ], 'encryption' => env('MAIL_ENCRYPTION', 'tls'), 'username' => env('MAIL_USERNAME'), 'password' => env('MAIL_PASSWORD'), 'sendmail' => '/usr/sbin/sendmail -bs', ];` – 06011991 Jul 31 '17 at 13:17
  • Check `config/services.php` here is the code from my `services.php` `'mailgun' => [ 'domain' => env('MAILGUN_DOMAIN'), 'secret' => env('MAILGUN_SECRET'), ],` – Kevin Patel Jul 31 '17 at 13:22
  • Yes, I have the same setup in my `services.php`. I did not change anything in `services.php`. – 06011991 Jul 31 '17 at 13:25
  • Check what I am getting in mail https://nimbus.everhelper.me/client/notes/share/1039913/0o2m4tvunf0r7lhl4qn5 – Kevin Patel Jul 31 '17 at 13:29
  • Yeah, I got you but I am not getting that way whatever I change it's not affecting? i don't understand – 06011991 Jul 31 '17 at 13:33
  • Can you try to send to any outlook email and please let me know how you are getting? – 06011991 Jul 31 '17 at 13:38
  • If you provided all information in .env then you will receive mail like I am receiving and check mailgun portal whether your domain is active or not. I already provided all configuration details which was required to configure mailgun in laravel – Kevin Patel Jul 31 '17 at 13:41
  • Actually I am not having any outlook email for testing – Kevin Patel Jul 31 '17 at 13:43
  • Oh okay. if you can try with outlook email, you will also get the same what I am getting. – 06011991 Jul 31 '17 at 13:52
-1

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.

http://mailgun-documentation.readthedocs.io/en/latest/faqs.html#email-clients-say-sent-via-mailgun-us-with-messages-i-send-how-do-i-get-rid-of-this

Otto
  • 879
  • 9
  • 7