Danaq's avatar
Level 1

Custom Mail Log channel breaks MAIL_DRIVER=log

I encountered an issue with the mail system of laravel 5.8. As the documentation says, Mail & Local Development one can change the way of sending emails to let it write them to a log-file.

Therefor, the .env as well as the config/mail.php-file have options for that. So, I added (the key was not here originally) a MAIL_LOG_CHANNEL-key to my .env-file with the value "mail" and changed the value of the key MAIL_DRIVER to "log".

Obviously, I added a new channel to the config/logging.php:

[...]
'mail' => [
            'driver' => 'single',
            'path' => storage_path('logs/mail-'.php_sapi_name().'.log'),
            'level' => 'info',
        ],
[...]

What ever I tried, the mail was never written to the seperate log-file. I testet the channel with a normal log-statement without any problem. I switched from MAIL_LOG_CHANNEL="mail" to MAIL_LOG_CHANNEL=mail added a default value to the section of the config/mail.php:

[before]
'log_channel' => env('MAIL_LOG_CHANNEL'),

[after]
'log_channel' => env('MAIL_LOG_CHANNEL', 'mail'),

not getting the width of a hair near to the log entry.

Only with the absolute basic configuration it actually writes the mail to the log but with this solution into the wrong log file.

Does anyone have an idea? It looks pretty strange to me.

Thanks for your help.

0 likes
2 replies
bobbybouwmann's avatar
Level 88

I think the level is incorrect here. Can you set it to debug to see if the emails show up in the log file then?

Also have you tried a simpler file name like storage_path('logs/mail.log'), just for testing purposes?

Danaq's avatar
Level 1

Thank you very much! It works as expected now.

From retrospective view it makes a lot of sense to me now :)

PS: The php_sapi_name()-function is only to prevent permission errors when log files are generated from cli as well as from http-requests. Maybe I wil change that to the permmission-attribute later but therefor I have to change my permission properties on my web-directories.

Thanks and have a nice day.

Please or to participate in this conversation.