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

henninghorn's avatar

Lumen 5.2 Mail not working

Mail doesn't seem to work after Lumen 5.2 update.

I'm using the facade

use Illuminate\Support\Facades\Mail;

And this is the error I'm getting when trying to do Mail::send()

ReflectionException in Container.php line 736:
Class mailer does not exist

It seems like some sort of binding isn't done correctly. Does anyone know how to fix this in Lumen 5.2.x?

0 likes
19 replies
bobbybouwmann's avatar

You need to add the mail package first

composer require illuminate\mail

Make sure you uncomment this

$app->register('App\Providers\AppServiceProvider'); to access the Mail ServiceProvider.
$app->withFacades(); to access the Mail facade.
henninghorn's avatar

@bobbybouwmann

Thanks for replying.

Unfortunately it doesn't work. I just tried installing a vanilla Lumen ( Lumen (5.2.4) (Laravel Components 5.2.*) ). But I'm getting the same error.

Does it work for you?

bobbybouwmann's avatar

You need to register the mail service provider as well. I currently don't have an installation running, but it should work fine!

henninghorn's avatar

@bobbybouwmann

I tried adding this:

$app->register(\Illuminate\Mail\MailServiceProvider::class);

The result changes this time, to this:

ErrorException in Manager.php line 77:
Missing argument 1 for Illuminate\Support\Manager::createDriver(), called in /home/vagrant/Code/testing/lumen52/vendor/illuminate/support/Manager.php on line 87 and defined

Something seems to be incompatible with Lumen. The installed Mail component is "illuminate/mail (v5.2.7)".

Seems like I'm getting closer. Any suggestions?

bobbybouwmann's avatar

@paroxp Lumen is currently at version 5.2.4, so that wouldn't be the case. However you can try it out ;)

jekinney's avatar

Lumen isn't designed to use the mailer. With that said the class should be under vender/Laravel folder. I haven't mess with lumen since 5.1 so maybe things have changed, but almost all of Laravel was in the vender/Laravel at that time.

paroxp's avatar

@bobbybouwmann Yes, you're right! My bad... It won't help.

@jekinney Surely, that's not the case. Mind, the idea is, to be able to pull different packages and use them in your project...

Now. I have dig a little, and here's the deal:

Lumen 5.1 Application class https://github.com/laravel/lumen-framework/blob/5.1/src/Application.php

Lumen 5.2 Application class https://github.com/laravel/lumen-framework/blob/5.2/src/Application.php

If you have a look, at the previous version, you'll find a method at line 667.

protected function registerMailBindings()

This method, is then passed into 'availableBindings' variable at 1751

        'mailer' => 'registerMailBindings',
        'Illuminate\Contracts\Mail\Mailer' => 'registerMailBindings',

It also has a class and facade registration at lines, 897 and 1705.

None of that, is existent in the version 5.2.

Therefore, we could say, Lumen has dropped the official support. Although, for sure you can modify/add these pieces in your AppServiceProvider for instance.

1 like
paroxp's avatar
paroxp
Best Answer
Level 1

Hello Again!

I've managed to solve the mystery.

I've installed lumen, required the illuminate/mail package, edited the bootstrap/app.php uncommenting the:

$app->withFacades();
[...]
$app->register(App\Providers\AppServiceProvider::class);

and now it get's tricky.

Open up your app/Providers/AppServiceProvider.php and in the register method, add the following:

        $this->app->singleton('mailer', function ($app) {
            $app->configure('services');
            return $app->loadComponent('mail', 'Illuminate\Mail\MailServiceProvider', 'mailer');
        });

This will enable the Mail once again.

NOTE: If you haven't got it already, you will need to copy/create the config/mail.php file: https://github.com/laravel/laravel/blob/master/config/mail.php

Once you have it in place, make sure to modify the 'from' key, otherwise you'll get Swift_TransportException.

Hope that helps anyone in the future!

5 likes
vipindasks's avatar
In bootstrap/app.php, uncomment line  $app->register(App\Providers\AppServiceProvider::class);
In bootstrap/app.php, uncomment line  $app->withFacades();
In the terminal run composer require illuminate/mail  (should download version ~5.2)

Update .env file to have appropriate username/password/etc for MAIL_DRIVER, MAIL_HOST, etc...

Add:

     "use Illuminate\Support\Facades\Mail;" 

at top of controller file where Mail will be sent from

Add:

       $app->register(Illuminate\Mail\MailServiceProvider::class);  

to bootstrap/app.php. Sending mail should work now. In some cases it may show this error:

        ErrorException in Manager.php line 77:
        Missing argument 1 for Illuminate\Support\Manager::createDriver(), 

To fix this, create a folder 'config' and create file 'mail.php'. it should contain exactly same settings as of in Laravel installation ( https://github.com/laravel/laravel/blob/master/config/mail.php). Open bootstrap/app.php.

Add :

        $app->configure('mail');
2 likes
siddaco_systems's avatar

Hi vipindasks. Its working for me. Great explanation in step by step. Thank you.

1 like
pedrolopes10's avatar

Hey, I manage the mail to work with your solution but I still have a problem.

I use a Schedule with the functions:
$schedule->command('test')->everyThirtyMinutes()->appendOutputTo($filePath)->emailOutputTo('plopes@airnavsystems.com'); and the function emailOutputTo() from Illuminate\Console\Scheduling\Event.php uses Illuminate\Contracts\Mail\Mailer; and injects with Mailer $mailer.

I got the error: Target [Illuminate\Contracts\Mail\Mailer] is not instantiable.

ospteam's avatar

@vipindasks I have tried as per your steps. It gives me error as Class 'Illuminate\Config\Repository' not found

1 like
vipindasks's avatar

@ospteam which version are you using. please try composer install. it seems vendor\laravel\framework\src\Illuminate\Config\Repository.php is missing.

ospteam's avatar

Thanks BTW. The path is different than what you have mentioned above and the Illuminate directory was missing so i have just added it from vendor\illuminate directory. vendor\laravel\lumen-framework\src\Illuminate\Config\Repository.php Thanks alot it works!

DonSchoeman's avatar

I'd like to add something for if you got this working according to the instructions in this thread but you don't want to use Facades. You can replace all your: Mail:: references with app('mailer')->

For example, instead of:

$recipients = ['[email protected]'];
Mail::raw('This is a test message.', function ($message) use ($recipients) {
    $message->subject('This is a test to see if emails are working');
    $message->to($recipients);
});

You can do this:

$recipients = ['[email protected]'];
app('mailer')->raw('This is a test message.', function ($message) use ($recipients) {
    $message->subject('This is a test to see if emails are working');
    $message->to($recipients);
});

Also, to make it a little cleaner you can add the following to your helpers.php (if you don't have one create one and then load it in your bootstrap/app.php:

if (! function_exists('mailer')) {
    /**
     * Returns the application mailer instance.
     *
     * @return \Illuminate\Mail\Mailer
     */
    function mailer()
    {
        return app('mailer');
    }
}

You can then call the mail functions like this:

$recipients = ['[email protected]'];
mailer()->raw('This is a test message.', function ($message) use ($recipients) {
    $message->subject('This is a test to see if emails are working');
    $message->to($recipients);
});
chimit's avatar

In Lumen 5.4 I just added this into my bootstrap/app.php:

$app->register(Illuminate\Mail\MailServiceProvider::class);

$app->configure('mail');
$app->configure('services');

These files can be grabbed from Laravel: https://github.com/laravel/laravel/blob/master/config/mail.php https://github.com/laravel/laravel/blob/master/config/services.php

$app->withFacades(); should be uncommented.

And make sure your .env file has the following settings (change for your needs):

MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
[email protected]
MAIL_FROM_NAME="Your company name"
idnetiti's avatar

@vipindasks Just upgraded from Laravel 6 to 7, and had an issue with a contact form. Your solution worked for me. Thank you!

Please or to participate in this conversation.