How to configure Laravel mail.php to use built-in mail function?

To use the email server running on localhost, your .env file should look like this (The PHP mail function doesn't need a username or a password)

MAIL_DRIVER=smtp
MAIL_HOST=localhost
MAIL_PORT=25
MAIL_USERNAME=
MAIL_PASSWORD=
MAIL_ENCRYPTION=null

Then, update the configuration cache:

php artisan config:cache

To do the same as mail() PHP function does, in most cases you should configure Laravel in the following way:

Use sendmail, at .env:

MAIL_DRIVER=sendmail

If you are using Larvel 7 or above

MAIL_MAILER=sendmail

Laravel 7 replaced MAIL_DRIVER by MAIL_MAILER

Host, user, password, port and encryption are not needed.

At this point, you may check if it already works, but sometimes the next step is also needed.

Set a new .env option in config/mail.php:

'sendmail' => env('MAIL_SENDMAIL', '/usr/sbin/sendmail -bs')

Set the sendmail path in .env. You can check sendmail_path at phpinfo(), but it's usually this one:

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

Tags:

Php

Email

Laravel