0

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@email.com", "$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.

eleven0
  • 263
  • 6
  • 13

1 Answers1

0

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:

MAIL_USERNAME=mymail@gmail.com
utdev
  • 3,942
  • 8
  • 40
  • 70
  • @eleven0 can you print it out to be sure – utdev Aug 20 '19 at 21:49
  • @eleven0 further post your whole email logic, there should be a to method, to which person you are sending the mail – utdev Aug 20 '19 at 21:50
  • again, that's exactly the question... I use forge my deployments and mail_from_address is in that file.... however as I stated in my original question, app is not able to read that variable from .env file.... why is that? (printing returns null) How do i solve that? PS: my email logic has those other fields..... Again, email sending works fine on local environment.... – eleven0 Aug 20 '19 at 21:59
  • So if you do this `dd(env('MAIL_FROM_ADDRESS'))` it returns null? Did you change anything in the config mail, which may overwrite this? Can you please post more code and the important part of your env file. Further check if in your config/auth there is nothing changed. I am out for now, I will have a look tomorrow if you provide more information. – utdev Aug 20 '19 at 22:04
  • I moved config:cache before config:clear in my deploy script and app was able to get the email address from .env file. – eleven0 Aug 21 '19 at 08:28