What's the correct configuration to send emails using Sendmail in Laravel?
Asked Answered
A

1

6

I am using Laravel 7 and I want to send an email using the Sendemail driver via Laravel Mail facade. It worked when I used the PHP mail function but I want to use the Laravel Mail facade instead.

My .env file email configuration:

MAIL_DRIVER=sendmail
MAIL_SENDMAIL='/usr/sbin/sendmail -t -i'

My default mail setup in config/mail.php:

'default' => env('MAIL_MAILER', 'sendmail'),
'mailers' => [
    'smtp' => [
        'transport' => 'smtp',
        'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
        'port' => env('MAIL_PORT', 587),
        'encryption' => env('MAIL_ENCRYPTION', 'tls'),
        'username' => env('MAIL_USERNAME'),
        'password' => env('MAIL_PASSWORD'),
    ],
    'ses' => [
        'transport' => 'ses',
    ],
    'sendmail' => [
        'transport' => 'sendmail',
        'path' => '/usr/sbin/sendmail -bs',
    ],
    'log' => [
        'transport' => 'log',
        'channel' => env('MAIL_LOG_CHANNEL'),
    ],
    'array' => [
        'transport' => 'array',
    ],
],

I have created Mail class as explained in the docs. What is the right configuration to make it work?

Average answered 6/6, 2020 at 11:36 Comment(3)
Maybe you should post from config/mail.php the sendmail section. Because that's the driver you are asking for.Daw
I have added the mailer section from config/mail.phpAverage
In laravel 7, env variable changed to MAIL_MAILER. You should specify driver with that keyRobbins
P
3

First, change the default MAIL_MAILER to use Sendmail.

MAIL_MAILER=sendmail

Then in config/mail.php, update the Sendmail line.

'sendmail' => [
    'transport' => 'sendmail',
    'path' => env('MAIL_SENDMAIL', '/usr/sbin/sendmail -bs')
],

Finally, if you need to change the MAIL_SENDMAIL value then add this line to your .env.

MAIL_SENDMAIL='/usr/sbin/sendmail -t -i'
Plumbum answered 6/9, 2020 at 3:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.