Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Email delivery

Laravel mail fails because an address does not comply with RFC 2822

ErrorSymfony\Component\Mime\Exception\RfcComplianceException: Email "" does not comply with addr-spec of RFC 2822.

Short answer

Symfony Mailer checks every address when the Address object is created. If the value is empty, null or not a plain address, it throws RfcComplianceException before any mail is sent. Dump the exact value that reaches to() or from(). It is usually an empty field or a 'Name <mail>' string passed to the wrong constructor.

  • Applies to Laravel 12, PHP 8.3, symfony/mime 7
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    The exception message prints the offending value between the quotes. Read it first, then log the variable that feeds the address.

    // just before Mail::to(...)
    logger()->info('mail recipient', ['to' => $user->email]);
  2. 2Match what you see, then jump to its fix

    1. 1The message shows Email "" with nothing between the quotesThe address variable is empty or nullFix
    2. 2The quoted value contains angle brackets and a display nameA 'Name <email>' string was given to the Address constructorFix
    3. 3The address contains accented or non-Latin characters and the failure appears when the server is contactedA non-ASCII address and an SMTP server that does not support itFix

What does the error look like?

  • Symfony\Component\Mime\Exception\RfcComplianceException: Email "" does not comply with addr-spec of RFC 2822.
  • Email "Jane Doe <jane@example.com>" does not comply with addr-spec of RFC 2822.

Cause 1 of 3

The address variable is empty or null

1Check

Symfony's Address class trims the string and then validates it. It has no special case for an empty value, so an empty string fails the same check as a bad one.

// in tinker
User::whereNull('email')->orWhere('email', '')->count();

2Fix

Make sure the value exists before you send, and validate it where the data enters the system.

if (filled($user->email)) {
    Mail::to($user->email)->send(new OrderShipped($order));
}

3Verify

Send to a user with an email address.

php artisan tinker --execute="Mail::to('test@example.com')->send(new App\Mail\OrderShipped(App\Models\Order::first()));"

Confirmed by raw.githubusercontent.com

Did this fix it?

Cause 2 of 3

A 'Name <email>' string was given to the Address constructor

1Check

new Address('Jane <jane@example.com>') validates the whole string as an address and fails. Only Address::create() parses the 'Name <email>' form.

grep -rn "new Address(" app/

2Fix

Pass the address and the name as two arguments, or use Address::create() for the combined string.

use Symfony\Component\Mime\Address;

new Address('jane@example.com', 'Jane Doe');
Address::create('Jane Doe <jane@example.com>');

3Verify

Send again; the exception no longer appears.

php artisan tinker --execute="echo Symfony\Component\Mime\Address::create('Jane Doe <jane@example.com>')->getAddress();"

Confirmed by raw.githubusercontent.com

Did this fix it?

Cause 3 of 3

A non-ASCII address and an SMTP server that does not support it

1Check

Symfony's mailer docs say non-ASCII characters are allowed in the local part and the domain, but you will see an exception if the SMTP server does not support it, and the sender address may not use a UTF-8 local part.

php artisan tinker --execute="echo config('mail.from.address');"

2Fix

Use an ASCII sender address, and an ASCII recipient address unless your SMTP provider supports internationalised addresses.

# .env
MAIL_FROM_ADDRESS=hello@example.com

3Verify

Send a test message again.

php artisan tinker --execute="Mail::raw('test', fn(\$m) => \$m->to('test@example.com'));"

Confirmed by symfony.com

Did this fix it?

How do I stop it coming back?

  • Validate email fields with the 'email' rule when the form is saved, so bad values never reach the mailer.
  • Skip or queue-fail cleanly for users without an address instead of letting the exception bubble.
  • Keep MAIL_FROM_ADDRESS plain ASCII.

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

Email

PHP mail() returns true but the email never arrives

Warning: mail(): "sendmail_from" not set in php.ini or custom "From:" header missing

mail() returning true only means the message was accepted for delivery, not that it arrived.

4 causes, each with a fix

Email

PHPMailer addCC() adds no CC recipient

The mail arrives for the To address but not for the CC address

addCC() returns false when it rejects the address, and PHPMailer then sends without that CC.

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.