Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

lara131141's avatar

Laravel 7 replaced MAIL_DRIVER by MAIL_MAILER

Note: I am using mailgun driver to deliver e-mail to Mailgun by API and not by SMTP.

The upgrade documentation of Laravel 7 talks about a Mail configuration change. I implemented the new configuration although the old configuration is still valid or compatible.

After implementing the new mail configuration my MAIL_DRIVER provider in the .env was not working anymore. Laravel wanted to send e-mail through smtp which was not configured and it throws out an exception.

The documentation of Laravel 7 still writes: To use the Mailgun driver, first install Guzzle, then set the driver option in your config/mail.php configuration file to mailgun. This is the same text as for Laravel 6 and is is not correct it seems.

I needed to replace MAIL_DRIVER by MAIL_MAILER in my .env file and set it to MAIL_MAILER=mailgun. Next, I opened the config/mail.php and added a new mailer like:

'mailgun' => [
            'transport' => 'mailgun',
        ],

And then it worked again. So before the MAIL_DRIVER skipped any other mail configuration and was using the information directly in config/services but now the flow is different.

Before: .env -> MAIL_DRIVER -> config/services -> Mailgun.

After: .env -> MAIL_MAILER -> config/mail -> config/services -> Mailgun

I think it is more logic but the documentation is not pointing this out. There is no driver option anymore. It is the transport option.

Anybody else noticing this?

0 likes
5 replies
jlrdw's avatar

He mentions the array, also It's optional.

lara131141's avatar

This is no answer.

But I was right. People using Mailgun driver and adapting the new Mail config from Laravel 7 brake their Mailgun functionality.

Laracast Business on Youtube addresses this issue. Check https://youtu.be/vcQD9tHy6Gg At least I found the solution myself just before the release of this video. Problem solved.

jlrdw's avatar

In env.example


MAIL_MAILER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"

So as said the array is discussed in the upgrade guide, so instead of using

MAIL_MAILER=smtp

Use

MAIL_MAILER=Mailgun

You would pick your mailer instead of smtp from the array.

So you followed the documentation.

Also note that this link: https://github.com/laravel/laravel/blob/develop/config/mail.php is given in the upgrade guide. And the code:

        'mailgun' => [
            'transport' => 'mailgun',
        ],

Is already included.

Sorry if I did not explain in greater detail, I thought you would see the link Taylor put there and look over the array on that Github page.

Also yes the mail chapter says driver option. But two things:

  • Laravel 7 is new
  • There are minor bugs sometimes at first.

How about do a pull request to correct the docs.

bionary's avatar

I too was perplexed trying to setup MailGun via their API for use with Laravel 8.

Thank you @xibel and @gotesla for pointing me in the right direction.

The docs in both Laravel (as of now) and MailGun are confusing. I'm confident it's easy to figure out if you've accomplished this many times before but painfully difficult if you haven't. (I spent many hours on this)

Let me point out a few things and wording inconsistencies along with some settings to help all future readers trying to use the MailGun API with Laravel (currently v.8) (note: this is NOT FOR smtp)

//config/mail.php

    'mailgun' => [
    	'transport' => 'mailgun',
	'domain' => env('MAILGUN_DOMAIN'),
	'secret' => env('MAILGUN_SECRET'),
    ],

this config assumes you are using .env... so MAILGUN_DOMAIN and MAILGUN_SECRET are setup in your .env file

// .env

MAIL_MAILER=mailgun
MAIL_PORT=2525
[email protected]
MAIL_FROM_NAME="${APP_NAME}"

#below is applied in config/mail.php
MAILGUN_DOMAIN=mailer.yourdomain.com
MAILGUN_SECRET=xyza1234515eabc123472dd9101f1xyz-abcd0167-abc12xyz

Mailgun recommends in their docs that you use a subdomain

MAILGUN_DOMAIN=mailer.yourdomain.com

so that's how I did my setup. mailgun will give you all the different DNS records to add, in order to verify the domain (or in my case sub.domain) that you will be using to verify the mail.

Note: Laravel examples call your API key "MAILGUN_SECRET" MailGun calls this your "Private API key" in one location of their dashboard and simply an "Api Key" under their php coding example.

In the very spot they list your "API Key" and provide some sample php code they also give you this misleading little trinket:

API base URL: https://api.mailgun.net/v3/mailer.yourdomain.com/mailgun.org

...or something like that. That is NOT your MAILGUN_DOMAIN that you use in your .env file.

you simply use the domain or sub.domain you setup with the DNS records eg: mailer.yourdomain.com (I kept getting mislead with that one)

MAILGUN_DOMAIN=mailer.yourdomain.com

Hopefully this helps some some people in the future.

Please or to participate in this conversation.