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

tbergman001's avatar

Laravel Mailer

I am having the worst time with the new mailers in v7, and need some help in understanding what may be going on.

Problem: When sending a mail via Mail::mailer('lab_connect')->to() Laravel does not listen to the from address set in the mail.php config file and instead uses the 'from' ['address'] entry in the mail.php config file. I have cleared the cache, restarted apache, but nothing seems to work.

I have 5 SMTP mailers configured which I send emails from, they are set up as follows:

MAIL_LC_MAILER=lab_connect
[email protected]
MAIL_LC_TRANSPORT=smtp
MAIL_LC_HOST=smtp.mailtrap.io
MAIL_LC_PORT=587
MAIL_LC_USERNAME=user
MAIL_LC_PASSWORD=pass
MAIL_LC_ENCRYPTION=tls

And then each has a different two character identifier.

In mail.php I have

'mailers' => [
        'main_smtp' => [
            'transport' => env('MAIL_MAIN_TRANSPORT'),
            'address' => env('MAIL_MAIN_FROM_ADDRESS'),
            'name' => env('MAIN_MAIL_FROM_NAME'),
            'host' => env('MAIL_MAIN_HOST'),
            'port' => env('MAIL_MAIN_PORT'),
            'encryption' => env('MAIL_MAIN_ENCRYPTION'),
            'username' => env('MAIL_MAIN_USERNAME'),
            'password' => env('MAIL_MAIN_PASSWORD'),
            'timeout' => null,
            'auth_mode' => null,
        ],
        'main_alert' => [
            'address' => env('MAIL_ALERT_FROM_ADDRESS'),
            'name' => env('MAIL_ALERT_FROM_NAME'),
            'transport' => env('MAIL_ALERT_TRANSPORT'),
            'host' => env('MAIL_ALERT_HOST'),
            'port' => env('MAIL_ALERT_PORT'),
            'encryption' => env('MAIL_ALERT_ENCRYPTION'),
            'username' => env('MAIL_ALERT_USERNAME'),
            'password' => env('MAIL_ALERT_PASSWORD'),
            'timeout' => null,
            'auth_mode' => null,
        ],
        'service_repair' => [
            'address' => env('MAIL_SR_FROM_ADDRESS'),
            'transport' => env('MAIL_SR_TRANSPORT'),
            'host' => env('MAIL_SR_HOST'),
            'port' => env('MAIL_SR_PORT'),
            'encryption' => env('MAIL_SR_ENCRYPTION'),
            'username' => env('MAIL_SR_USERNAME'),
            'password' => env('MAIL_SR_PASSWORD'),
            'timeout' => null,
            'auth_mode' => null,
        ],
        'customer_service' => [
            'address' => env('MAIL_CS_FROM_ADDRESS'),
            'transport' => env('MAIL_CS_TRANSPORT'),
            'host' => env('MAIL_CS_HOST'),
            'port' => env('MAIL_CS_PORT'),
            'encryption' => env('MAIL_CS_ENCRYPTION'),
            'username' => env('MAIL_CS_USERNAME'),
            'password' => env('MAIL_CS_PASSWORD'),
            'timeout' => null,
            'auth_mode' => null,
        ],
        'lab_connect' => [
            'transport' => env('MAIL_LC_TRANSPORT'),
            'host' => env('MAIL_LC_HOST'),
            'port' => env('MAIL_LC_PORT'),
            'encryption' => env('MAIL_LC_ENCRYPTION'),
            'address' => env('MAIL_LC_FROM_ADDRESS'),
            'name' => env('MAIL_LC_FROM_ADDRESS'),
            'username' => env('MAIL_LC_USERNAME'),
            'password' => env('MAIL_LC_PASSWORD'),
            'timeout' => null,
            'auth_mode' => null,
        ],
    ],

And then finally I am sending via

Mail::mailer('lab_connect')->send(new SoftwareActivated_LabConnect($license, $license->contact_email));

If I change the from in the mail.php folder like the below

'from' => [
        'address' => env('MAIL_LC_FROM_ADDRESS'),
        'name' => env('MAIL_MAIN_FROM_NAME'),
    ],

everything works, however I need laravel to listen to the mailer and not use the default.

0 likes
1 reply
tbergman001's avatar

Update, I was able to get this after some trial and error.

This is correct:

'lab_connect' => [
            'transport' => env('MAIL_LC_TRANSPORT'),
            'host' => env('MAIL_LC_HOST'),
            'port' => env('MAIL_LC_PORT'),
            'encryption' => env('MAIL_LC_ENCRYPTION'),
            'from' => [
                'address' => env('MAIL_LC_FROM_ADDRESS'),
                'name' => env('MAIL_LC_FROM_ADDRESS'),
            ],
            'username' => env('MAIL_LC_USERNAME'),
            'password' => env('MAIL_LC_PASSWORD'),
            'timeout' => null,
            'auth_mode' => null,
        ],

Please or to participate in this conversation.