Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

Laravel mail fails because no From address is set

ErrorCannot send message without a sender address

Short answer

Laravel needs a From address for every message. Set a global one in config/mail.php, read from MAIL_FROM_ADDRESS, or set from in the mailable's envelope. If you already set it in .env and nothing changes, the config is cached and the .env file is no longer read: clear it.

  • Applies to Laravel 12, PHP 8.3
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Print the From address Laravel will really use. An empty or placeholder value points at the cause.

    php artisan config:show mail.from
  2. 2Match what you see, then jump to its fix

    1. 1config:show shows an empty address, or the placeholder hello@example.comNo global from address is configuredFix
    2. 2The .env value is right but config:show still shows the old addressThe configuration is cached, so .env changes are ignoredFix
    3. 3Most mail works, one mailable sends from the wrong or no addressOne mailable needs its own senderFix

What does the error look like?

  • Cannot send message without a sender address
  • Mail sent from Laravel has no From address, or the default hello@example.com

Cause 1 of 3

No global from address is configured

1Check

The global from address in config/mail.php is used whenever the mailable names none. Check what it reads from the environment.

grep -n "MAIL_FROM" .env config/mail.php

2Fix

Set the global address and name in the environment file, and make sure config/mail.php reads them.

# .env
MAIL_FROM_ADDRESS="noreply@example.com"
MAIL_FROM_NAME="Example"

// config/mail.php
'from' => [
    'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'),
    'name' => env('MAIL_FROM_NAME', 'Example'),
],

3Verify

config:show prints the new address.

php artisan config:show mail.from

Confirmed by laravel.com

Did this fix it?

Cause 2 of 3

The configuration is cached, so .env changes are ignored

1Check

Once config:cache has run, the .env file is not loaded during requests or Artisan commands. env() then returns only real system environment variables, and the cached values win.

ls bootstrap/cache/config.php

2Fix

Clear the cached configuration, or rebuild it with the new values as part of the deploy. Also call env() only inside config files, never in application code.

php artisan config:clear
# production: rebuild after the change
php artisan config:cache

3Verify

config:show now prints the .env address.

php artisan config:show mail.from

Confirmed by laravel.com

Did this fix it?

Cause 3 of 3

One mailable needs its own sender

1Check

A from set in the mailable overrides the global one. A mailable that builds its envelope without from falls back to the global address.

grep -rn "new Envelope" -A 4 app/Mail/

2Fix

Set from in the mailable's envelope.

use Illuminate\Mail\Mailables\Address;
use Illuminate\Mail\Mailables\Envelope;

public function envelope(): Envelope
{
    return new Envelope(
        from: new Address('billing@example.com', 'Billing'),
        subject: 'Your invoice',
    );
}

3Verify

Send that mailable and read the From header of the received message.

php artisan tinker

Confirmed by laravel.com

Did this fix it?

How do I stop it coming back?

  • Add MAIL_FROM_ADDRESS to .env.example so every environment has it.
  • Use an address on a domain your mail provider has verified.
  • Run config:cache in the deploy script after the environment file is updated.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Back end

composer require maatwebsite/excel fails to install

Composer says the package needs an older PHP than the one installed

Composer refuses maatwebsite/excel when the PHP version or a PHP extension does not match what the package and PhpSpreadsheet need.

3 causes, each with a fix

Back end

composer require laravel/horizon fails: ext-pcntl is missing

laravel/horizon v1.1.0 requires ext-pcntl * -> the requested PHP extension pcntl is missing from your system

Horizon needs the pcntl extension, and Composer refuses to install it where PHP lacks that extension.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.