sending email from laravel using the mailgun can't set the FROM properly

345 views Asked by At

This is the way which I send the email:

Mail::send('emails.welcome', $data, function($message)
{
    $message->from('[email protected]', 'Laravel');

    $message->to('[email protected]')->cc('[email protected]');

    $message->attach($pathToFile);
});

This is my mail configurations:

return [

    'driver' => env('MAIL_DRIVER', 'mailgun'),

    'host' => env('MAIL_HOST', 'smtp.mailgun.org'),

    'port' => env('MAIL_PORT', 587),

    // 'from' => ['address' => '', 'name' => ''], //

    'encryption' => 'tls',

    'username' => env('****'),

    'password' => env('****'),

    'sendmail' => '/usr/sbin/sendmail -bs',

    'pretend' => false,
];

This is my services configurations:

'mailgun' => [
            'domain' => '****',
            'secret' => '****',
        ],

When I get the email I see FROM is set to([email protected]). I would like to use different FROM based on different conditions, I don't want to hard code the FROM in the mail configurations. Please help.

1

There are 1 answers

0
Nicklas Kevin Frank On

The only potential problem I can spot, seems to be that you have commented out from in your mail configurations

'port' => env('MAIL_PORT', 587),

// 'from' => ['address' => '', 'name' => ''], //

'encryption' => 'tls',

This could be causing the problem with ->from not correctly overriding, as it might be dependent on it.