IpsumDolor's avatar

For reference: »An email must have a "From" or a "Sender" header.«

Hi! I just upgraded an existing Laravel 8.latest app to Laravel 9 with the new Symfony mailer. I got the following error:

The following exception occurred during the request:
Symfony\Component\Mime\Exception\LogicException: An email must have a "From" or a "Sender" header. in \vendor\symfony\mime\Message.php:132

Before with the old mailer, I did not need to set a sender - it could be empty. And this was the case in testing, because I didn't had it set in .env.testing. It was set to null.

This needs to be set in your .env or .env.testing to pass tests if you use the new mailer: [email protected]

Maybe this helps for future reference - it debugged it for 45 minutes and felt stupid in the end 🙈

0 likes
14 replies
Sinnbeck's avatar

Thanks for the info. This is bound to come up again :)

1 like
MB's avatar

Remember to run php artisan config:clear

1 like
mmai's avatar

Thank you very much! I had the same problem after upgrading to 9.x and running my tests and your post saved me a lot of time!

Squadz's avatar

Same here when testing Fortify, thanks! 👍

BrickZ28's avatar

Thank you for saving some time in troubleshooting

1 like
mpilot-aleks's avatar

I have a passing test, then suddenly failing due to this error. This really saved me. Thanks mate! Cheers!

Farkhad's avatar

I'm sending notifications using standard Laravel 9.x Notifications. I have to explicitly call from method in order to avoid exception "An email must have a "From" or a "Sender" header."

/**
     * Get the mail representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return \Illuminate\Notifications\Messages\MailMessage
     */
    public function toMail($notifiable)
    {
        // TODO notification should work without explicit ->from(...)
        // currently if not present it throws exception
        return (new MailMessage)
                    ->from(config('mail.from.address'), config('mail.from.name'))
                    ->greeting('Hello ' . $notifiable->name)
                    ->line('The introduction to the notification.')
                    ->action('Notification Action', url('/'))
                    ->line('Thank you for using our application!');
    }
samar92's avatar

I added MAIL_FROM_ADDRESS=[email protected] as mentioned but i still get the same error

An email must have a "From" or a "Sender" header.

any help please?

Please or to participate in this conversation.