I am using Laravel 9.16, sendgrid 7.11, php 8.0, and the illuminate mail facade
(This code worked with the previous versions of php and sendgrid.)
Whenever I try to send an email I am getting the following error:
Email "" does not comply with addr-spec of RFC 2822.
I have broken my code into separate steps so I can see if things are being set properly.
$this_mailable= new WelcomeEmail($customer);
$mail_facade = Mail::to('[email protected]');
$mail_facade->send($this_mailable);
After I set the mail_facade to it looks like this:
$mail_facade = {IlluminateMailPending}
to = {array}
[0] = '[email protected]'
Yet when I call the send it returns that error (as if the to is not set)
The from is set in the mailer object which is an object inside of the facade.
When I user the default to in my development environment (similar to what I am using for the from) the email is sent so I don’t believe the from is my issue.
2
Answers
This was such a dumb mistake but I wanted to post in case anyone else would make the same mistake. I had code in the config/mail.php file that would set the global to email. (reading it from my .env file) When I didn't have a variable in the .env file it would try to override the email I was sending in the to with a null value for the global to.
I think as Tim Lewis mentioned in the comment above should work, what you will need is to get the user email before actually selecting the Mailable class that you want to work with!
Correct me if I am wrong!