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

ThePenguin's avatar

Mail notification won't send, Mail::Raw will

I have configured my SMTP server correctly in Laravel's env file, and can successfully send an email using Mail::raw e.g.

Mail::raw("This is a test message", function ($message) { $message->from(env("MAIL_ORDER_ADDRESS"), 'Orders'); $message->to('[email protected]'); $message->subject('Test Message'); });

However, when I use a laravel 5.3 mail notification, no email is received (nor is an error generated). I have tested the same notification code locally using mail trap and the notifications work correctly.

I can't understand how if the mail server is working and can be used with Mail::raw, it doesn't automatically work with notifications when I have tested locally and confirm they are coded correctly.

Note: Using shared hosting on NameCheap.

Any ideas?

0 likes
3 replies
ThePenguin's avatar

OMG! I'm such an idiot. It was because I had not configured "From" in config/mail.php and because the domains didn't match, it wasn't set.

topherjamesknoll's avatar

Hmm... This is strange. I've never had a problem with this before. Though, my emails weren't sending either all the sudden. I never touch the config/mail config file. I use the .env file. But after reading this I said to myself what the hey and tried it. Of course when I modified the from fields to exactly what I have in my .env file, it worked. So my question is why is it not just simply pulling the info from my .env file???

'from' => [
        'address' => env('MAIL_FROM_ADDRESS', '[email protected]'),
        'name' => env('MAIL_FROM_NAME', 'Example'),
    ],

doesn't work. While

'from' => [
        'address' => '[email protected]',
        'name' => 'Allen Wrench',
    ],

seems to work fine. :/

topherjamesknoll's avatar

Ha! Never mind. I guess MAIL_FROM_ADDRESS and MAIL_FROM_NAME aren't even in the .env file. Anyway I just put my from email address and from name as alternatives to the .env values as it's not really sensitive information anyway:

    'from' => [
        'address' => env('MAIL_FROM_ADDRESS', '[email protected]'),
        'name' => env('MAIL_FROM_NAME', 'Allen Wrench'),
    ],

Hope this helps anyone that needs it!

Please or to participate in this conversation.