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

时间:2014-02-03 14:59:36

标签: php email laravel laravel-4 swiftmailer

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

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

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

$email = email@address.com

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

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

以下是块:

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

16 个答案:

答案 0 :(得分:12)

由于范围的原因,您的电子邮件变量为空,您应该设置一个使用条款,例如:

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

答案 1 :(得分:3)

(我在PHP中使用SwiftMailer)

当我不小心为$ email发送字符串时,我收到了类似的错误

$email = "someone@somewhere.com <Some One>";

当我打算发送的内容是

$email = Array("someone@somewhere.com"=>"Some One");

我不小心通过我用于记录的stringify函数运行它,所以一旦我再次开始发送数组,错误便消失了。

答案 2 :(得分:3)

确保您的电子邮件地址变量不为空。 检查使用

的print_r($ variable_passed);

答案 3 :(得分:1)

我遇到了同样的问题,我已经修好了。请确保一些事情如下所示:

   Mail::send('emails.auth.activate', array('link'=> URL::route('account-activate', $code),'username'=>$user->username),function($message) use ($user) {
                        $message->to($user->email , $user->username)->subject('Active your account !');

                    });

这应该是 emails.activation

    Hello {{ $username }} , <br> <br> <br>

    We have created your account ! Awesome ! Please activate by clicking the   following link <br> <br> <br>
   ----- <br>
      {{ $link }} <br> <br> <br>
       ---- 

为什么你不能将$ email变量调用到你的邮件发送功能的答案。您需要调用$ user变量,然后您可以将所需的变量写为$ user-&gt; variable

谢谢你:)

答案 4 :(得分:1)

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

我不知道为什么,但在我的情况下,我将from的信息放在函数中并且它工作正常。

答案 5 :(得分:1)

因为发送的电子邮件地址是空白的。看到那些空括号?这意味着电子邮件地址没有放在swiftmailer函数的$地址中。

答案 6 :(得分:0)

数据变量($ email,$ subject)似乎是全球性的。并且全局变量无法在函数内部读取。您必须将它们作为参数传递(推荐方式)或将它们声明为全局。

尝试这种方式:

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

答案 7 :(得分:0)

当$ email变量为空或有时邮件不存在时会发生这些错误,请尝试使用现有邮件

答案 8 :(得分:0)

试试这个。

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

答案 9 :(得分:0)

我今天遇到了类似的问题,解决方案就是这样......

$email = Array("Zaffar Saffee" => "myemail@gmail.com");
        $schedule->command('cmd:mycmd')
                 ->everyMinute()
                 ->sendOutputTo("/home/forge/dev.mysite.com/storage/logs/cron.log")
                 ->emailWrittenOutputTo($email);

它虽然是laravel 5.2 ......

我的基本问题是,我传递字符串而不是数组,所以错误是

->emailWrittenOutputTo('mymail@gmail.com'); // string, we need an array

答案 10 :(得分:0)

  

[已解决] Neos / swiftmailer:给定的邮箱中的地址[]不符合RFC 2822,3.6.2

     

/var/www/html/vendor/Packages/Libraries/swiftmailer/swiftmailer/lib/classes/Swift/Mime/Headers/MailboxHeader.php中第261行的异常:给定邮箱中的地址[]不符合RFC 2822,3.6.2。

    private int GetRating(Ratings ratings, double rawValue)
    {
        int finalRating = 0;

        if (rawValue <= ratings.Rating_1_upperLimit)
            finalRating = 1;

        else if ( rawValue <= ratings.Rating_2_upperLimit)
            finalRating = 2;

        else if( rawValue <= ratings.Rating_3_upperLimit)
            finalRating = 3;

        else if( rawValue <= ratings.Rating_4_upperLimit)
            finalRating = 4;
        else 
            finalRating = 5;

        return finalRating;
    }
  

https://discuss.neos.io/t/solved-neos-swiftmailer-address-in-mailbox-given-does-not-comply-with-rfc-2822-3-6-2/3012

答案 11 :(得分:0)

您的问题可能是.env文件未正确加载并使用MAIL_USERNAME。

要检查您的.env文件是否正确加载了电子邮件地址,请将此行添加到您的控制器并刷新页面。

dd(env('MAIL_USERNAME') 

如果显示为空,请尝试从命令行运行以下命令,然后重试。

php artisan cache:clear

答案 12 :(得分:0)

唯一适用于我的解决方案是更改以下代码

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

答案 13 :(得分:0)

对于 Laravel < v7 : from email address 可以在结尾或开头包含一个空格

对于 Laravel >= 7 :发件人电子邮件地址必须符合 RFC,即邮件地址的末尾或开头不应有任何空格

为了安全起见,看看您是否可以在实际调用邮件程序类之前修剪电子邮件地址

答案 14 :(得分:0)

我的解决方案是将我的 QUEUE CONNECTION 从数据库切换到 Redis。

答案 15 :(得分:0)

当收件人电子邮件为空时会发生这种情况。

尝试打印 $email 以检查它是否有价值。