给定 [] 邮箱中的地址不符合 RFC 2822, 3.6.2.当电子邮件在变量中时

2022-01-08 00:00:00 email php laravel laravel-4 swiftmailer

我有一个正确的电子邮件地址.我已经回显了它,但是当我发送它时,我收到以下错误:

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. 

为什么?我使用 laravel (swift mailer) 发送电子邮件:

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

$email = email@address.com

然后当我发送它时,就会抛出错误.

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

但如果我直接使用字符串,它会发送它.

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

这里是块:

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

推荐答案

你的email变量因为作用域是空的,你应该设置一个use子句比如:

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);
});

相关文章