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

后端 未结 13 2235
执笔经年
执笔经年 2020-12-16 09:52

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,          


        
相关标签:
13条回答
  • 2020-12-16 10:17

    I had very similar problem today and solution was as it is..

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

    It laravel 5.2 though...

    my basic problem was , I was passing string instead of array so, error was

    ->emailWrittenOutputTo('mymail@gmail.com'); // string, we need an array
    
    0 讨论(0)
  • 2020-12-16 10:19

    Its because the email address which is being sent is blank. see those empty brackets? that means the email address is not being put in the $address of the swiftmailer function.

    0 讨论(0)
  • 2020-12-16 10:23

    Try this.

    Mail::send('emails.activation', $data, function($message) use($email,$subject){
                $message->to($email)->subject($subject);
            });
                    ->with('title', "Registered Successfully.");
    
    0 讨论(0)
  • 2020-12-16 10:26

    Your problem may be that the .env file is not loading properly and using the MAIL_USERNAME.

    To check if your .env file is loading the email address properly add this line to your controller and refresh the page.

    dd(env('MAIL_USERNAME') 
    

    If it shows up null try running the following command from command line and trying again.

    php artisan cache:clear
    
    0 讨论(0)
  • 2020-12-16 10:28

    (I'm using SwiftMailer in PHP)

    I was getting an error like that when I was accidentally sending a string for $email

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

    When what I meant to be sending was

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

    I was accidentally running it through a stringify function that I was using for logging, so once I started sending the array again, the error went away.

    0 讨论(0)
  • 2020-12-16 10:31

    The only solution worked for me is changing the following code

     Mail::send('emails.activation', $data, function($message){
         $message->from(env('MAIL_USERNAME'),'Test'); 
         $message->to($email)->subject($subject);
    });
    
    0 讨论(0)
提交回复
热议问题