555 5.5.2 Syntax error. gmail's smtp

2019-01-15 12:53发布

问题:

Do you know what is syntax error refering?

Here's the code I'm using cakephp

 $User = $this->User->read(null,$id);
    $this->Email->to = array('name@gmail.com');; 
    $this->Email->from = 'name@gmail.com';
    $this->Email->subject = 'Welcome to our really cool thing';
    $this->Email->template = 'simple_message'; 

    $this->Email->sendAs = 'both'; 
     $this->Email->smtpOptions = array(
        'port'=>'465', 
        'timeout'=>'30',
        'auth' => true,
        'host' => 'ssl://smtp.gmail.com',
        'username'=>'name@gmail.com',
        'password'=>'********',

   );
    $this->set('User', $User);
    $this->Email->delivery = 'smtp';
    $this->Email->send();

NOTE: I'm sending the email to myself for test purposes.

回答1:

This question was asked here: Cakephp SMTP emails syntax error

Here is RabidFire's (correct) answer:

Google's SMTP requires you to format email addresses in the following way:

Recipient Name <myname@example.com>

Do this for both the from and to address, and you should be good to go. If you don't have the name of the user, then you can just repeat the email:

$this->Email->to = "my_test_mail@centrum.cz <my_test_mail@centrum.cz>";



回答2:

Just got one of these today, a library I'm using puts the site name in square brackets before sending the mail and causes the 555 5.5.2 Syntax Error.

Your best off having no symbols in the first part of the addres where name should go. My error was caused by

"Name [Site] <address@site.com>"

and fixed by

"Name Site <address@site.com>"


回答3:

setting to and from as "email@email.com <email@email.com>" was't working for me. Had to change both to "<email@email.com>". Putting a string outside the <> part fails with "Mail send failed 555 5.5.2 Syntax error. .. - gsmtp"



回答4:

I've got this error when "from" field was empty or not valid. So you shouldn't use fake email in your test.



回答5:

I had this problem with but with an email like dude.muñoz@domain.com and solved changing to dude.mu&#241oz@domain.com (Changing the special characters with unicodes).



标签: email smtp