22

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.

juan
  • 271
  • 1
  • 4
  • 11
  • Perhaps a few more details are in order. Like, the email causing this error, how you're sending it, where you're sending it from, etc... Until then, this question is "it's broken. fix it. you don't need any more details" – Marc B Dec 01 '10 at 05:04
  • Of course sorry I fixed already – juan Dec 01 '10 at 05:12
  • if it's fixed, post an answer for us? Was it an ssl cert issue? – zanlok Dec 09 '10 at 21:18
  • possible duplicate of [Cakephp SMTP emails syntax error](http://stackoverflow.com/questions/4421866/cakephp-smtp-emails-syntax-error) – YasirA Aug 23 '11 at 10:50

8 Answers8

27

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>";

Community
  • 1
  • 1
Chaim
  • 2,109
  • 4
  • 27
  • 48
  • 1
    When using python's smtplib, I was receiving the same error. In that circumstance, if you use the name you will still get a syntax error. Leave the name out and it will be fine (include the <>). – Shane Chin Nov 11 '11 at 20:14
6

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"

  • 1
    For me, it failed with that error when the TO address had a string outside the <> but the FROM address was fine with a string outside the <>. Thankfully so, otherwise you can't put any nice looking name. It's possible this has changed and may change again. – Michael K Jan 24 '20 at 16:23
3

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>"
iNulty
  • 923
  • 8
  • 17
1

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).

i31nGo
  • 1,422
  • 15
  • 11
0

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

Sergey V.
  • 840
  • 8
  • 15
0

Put the "YourName" inside <> brackets in sender field.

I'm using Erlang, Vagabond/gen_smtp and Gmail.

This is a part of my config file:

{email_conf, [
  {sender, <<"<YourName your_gmail_address@gmail.com>">>},
  {options, [
    {ssl, true},
    {port, 465},
    {relay, <<"smtp.gmail.com">>},
    {username, <<"your_gmail_address@gmail.com">>},
    {password, <<"...">>}
  ]}
]},

and function:

send_html(Subject, Body, Sender, Receiver, Opts) ->
  Mimemail =
    {<<"text">>, <<"html">>,
      [
        {<<"From">>, Sender},
        {<<"To">>, Receiver},
        {<<"Subject">>, Subject},
        {<<"Content-Type">>, <<"text/html; charset=utf-8">>}
      ],
      [{<<"transfer-encoding">>, <<"base64">>}],
      Body},
  Mail = {Sender, [Receiver], mimemail:encode(Mimemail)},
  gen_smtp_client:send_blocking(Mail, Opts).
Ukr
  • 2,411
  • 18
  • 16
0

We solved this issue just by removing the name

"Name <address@site.com>"

Replaced by

"address@site.com"
Corentin Geoffray
  • 705
  • 2
  • 7
  • 12
0

Its Due to message format is not correct. may be from address or to address is wrong(like a extra comma something)

Sarath PK
  • 1
  • 1