Address in mailbox given [] does not comply with RFC 2822, 3.6.2. when email is in a variable

user3077503 picture user3077503 · Feb 3, 2014 · Viewed 118.6k times · Source

I have a correct email address. I have echoed it, but when I send it, I get the following error:

 Address in mailbox given [] does not comply with RFC 2822, 3.6.2. 

Why? I use laravel (swift mailer) to send email:

$email = [email protected]

and then when I send it, the error is thrown.

But if I directly use the string, it sends it.

Here is the block:

 Mail::send('emails.activation', $data, function($message){
            $message->to($email)->subject($subject);
        });
                ->with('title', "Registered Successfully.");

Answer

Juanjo Lainez Reche picture Juanjo Lainez Reche · Jun 4, 2014

Your email variable is empty because of the scope, you should set a use clause such as:

Mail::send('emails.activation', $data, function($message) use ($email, $subject) {
    $message->to($email)->subject($subject);
});