Laravel - Swift_RfcComplianceException only on staging server .env file problem

239 Views Asked by At

I have a problem on my staging environment while the problem does not occur in my local env.


        ->from(env('MAIL_FROM_ADDRESS'), "$user->firstname $user->lastname")

it gives me following error;

(1/1) Swift_RfcComplianceException
Address in mailbox given [] does not comply with RFC 2822, 3.6.2.

It seems that app is not able to get the mail_from_address from my .env file. Why is this happening as everything works fine in my local environment?

I have these in my deploy script as well,

composer dump-autoload

# Clear caches
php artisan cache:clear
php artisan auth:clear-resets

php artisan config:clear
php artisan config:cache
php artisan view:clear

What am I missing here? Any suggestion? Is the problem something else?

EDIT 2: I actually hard coded my from address as below and everything worked fine.... So question is how come app is not reading .env file? Is this some type of a cache problem?


        ->from("[email protected]", "$user->firstname $user->lastname")

Edit 1: 'MAIL_FROM_ADDRESS' exixts in my .env file.

EDIT 3: SOLUTION

I moved config:cache before config:clear in my deploy script and app was able to get the email address from .env file.

1

There are 1 best solutions below

5
On

Well this error tells, that you have actually no email

(1/1) Swift_RfcComplianceException
Address in mailbox given [] does not comply with RFC 2822, 3.6.2.

If there are for instance any syntax errors in your mail address it would have returned something like this:

(1/1) Swift_RfcComplianceException
Address in mailbox given [myfalsemail§@gmail.com] does not comply with RFC 2822, 3.6.2.

Further did you run a config cache command, if yes clear your config's cache just to be sure:

php artisan config:clear

But mostly likely your email is empty, try to print this:

dd(env('MAIL_FROM_ADDRESS'))

If it is empty add an email in your .env file like this:

[email protected]