110mb.com Forum
News: All accounts on B15 registered before 28 Aug are gone. Please register it again and reupload your files. All data restored. Will begin synchronizing your old data files with new starting on 8th Sept.
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
September 08, 2008, 01:35:21 AM


Login with username, password and session length


Pages: [1]   Go Down
  Send this topic  |  Print  
Author Topic: Getting a 555 5.5.2 Syntax error in smtp [in need of assistance]  (Read 244 times)
uberwalla
Python Expert
Hyper-Active Member
***
Offline Offline

Posts: 423


WWW
« on: July 23, 2008, 04:19:22 AM »

Trying at a new take at my own smtp script. Rather than using phpmailer. I finally got past where I was with my old script (response wise) but I have a new problem.

It started when I got the 555 5.5.2 Syntax error on the MAIL FROM header. And then when I added < > around the email it worked and then moved on. Next I had the same error for RCPT TO, but if I put the < > brackets around the email, the script doesn't load at all.

Anyways I am at a loss of how I can get past. This is what I have:

Code:
<?php
function smtp($from, $namefrom, $to, $nameto, $subject, $message) {
$username = "!removed!";
$password = "!removed!";
$newLine = "\r\n";

$smtpConnect = fsockopen("ssl://smtp.gmail.com:465", 25, $errno, $errstr, 15);
$smtpResponse = fgets($smtpConnect, 515);

if($smtpConnect) {
$logArray['connect'] = $smtpResponse;
}

fputs($smtpConnect, "HELO localhost" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['helo'] = $smtpResponse;

fputs($smtpConnect,"AUTH LOGIN" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['auth'] = $smtpResponse;

fputs($smtpConnect, base64_encode($username) . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['user'] = $smtpResponse;

fputs($smtpConnect, base64_encode($password) . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['pass'] = $smtpResponse;

fputs($smtpConnect, "MAIL FROM: <$from>" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['from'] = $smtpResponse;

fputs($smtpConnect, "RCPT TO: $to" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['to'] = $smtpResponse;

fputs($smtpConnect, "DATA" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['data'] = $smtpResponse;

$headers  = "MIME-Version: 1.0" . $newLine;
$headers .= "Content-type: text/plain; charset=iso-8859-1" . $newLine;
$headers .= "To: $nameto <$to>" . $newLine;
$headers .= "From: $namefrom <$from>" . $newLine;

fputs($smtpConnect, "To: $to\nFrom: $from\nSubject: $subject\n$headers\n\n$message\n.\n");
$smtpResponse = fgets($smtpConnect, 515);
$logArray['message'] = $smtpResponse;

fputs($smtpConnect, "QUIT" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['quit'] = $smtpResponse;

echo nl2br(var_export($logArray));
}

$to = "!removed!";
$nameto = "!removed!";
$from = "!removed!";
$namefrom = "!removed!";
$subject = "Hello World Again!";
$message = "World, Hello!";
smtp($from, $namefrom, $to, $nameto, $subject, $message);
?>


The responses I get are:
Quote
'connect' => '220 mx.google.com ESMTP p27sm8715819qbp.15'
'helo' => '250 mx.google.com at your service'
'auth' => '334 VXNlcm5hbWU6'
'user' => '334 UGFzc3dvcmQ6'
'pass' => '235 2.7.0 Accepted'
'from' => '250 2.1.0 OK'
'to' => '555 5.5.2 Syntax error. p27sm8715819qbp.15'
'data' => '503 5.5.1 RCPT first. p27sm8715819qbp.15'
'message' => '502 5.5.1 Unrecognized command. p27sm8715819qbp.15'
'quit' => '502 5.5.1 Unrecognized command. p27sm8715819qbp.15'

Help is much appreciated. Thanks in advance.
Logged

uberwalla
Python Expert
Hyper-Active Member
***
Offline Offline

Posts: 423


WWW
« Reply #1 on: July 25, 2008, 12:05:00 AM »

anybody have any ideas? Still having same problems. I though also maybe it was something with google, so I waited a while, but still getting a syntax error. And I don't see anything wrong with my syntax  huh
Logged

RBCFAQS
110MB Dreamweaver Expert and
Loyal 110MB Member
*******
Offline Offline

Posts: 2342


I need Ubuntu Wireless Network help.


WWW
« Reply #2 on: July 25, 2008, 07:57:34 AM »

http://groups.google.com/group/hosted-setup/browse_thread/thread/09fa938a9ac3f7b3

http://groups.google.com/group/hosted-the-basics/browse_thread/thread/92b9fba1c4a82430

http://www.google.com/search?hl=en&rlz=1G1GGLQ_ENUS252&q=555+5.5.2+Syntax+error&btnG=Search for my search results.
Logged

uberwalla
Python Expert
Hyper-Active Member
***
Offline Offline

Posts: 423


WWW
« Reply #3 on: July 25, 2008, 09:03:31 AM »

Thanks a lot, but I tried that though. Most of them are about syntax errors other than rcpt to and or they are for ruby and stuff which didn't really help my error.
Logged

bind
just a man
Authority Member
****
Offline Offline

Posts: 593


« Reply #4 on: July 25, 2008, 12:43:23 PM »

are you sure this line is correct ?

Code:
fputs($smtpConnect, "To: $to\nFrom: $from\nSubject: $subject\n$headers\n\n$message\n.\n");

shouldnt the eol's (end of line) be \n\r instead of \n ?

and whats the period for between the last 2 eol's after $messages ??
Logged

"... if you give a man a fish, he eats today ... if you teach a man to fish, he eats for the rest of his life ..."

That means I am not here to do your work for you, but to assist you in learning how to code what you need. If you want someone to code for you, hire someone to do it or use an out of the box app. All unsolicited pm's are deleted without reading.
inp o҉rtb
The Gangsta
Global Moderator
Official 110mb Guru
*****
Offline Offline

Posts: 9785

experimental theologian


WWW
« Reply #5 on: July 25, 2008, 01:12:24 PM »

In SMTP, \n.\n means end of message.
Logged


blog | my work @ deviantART | please add your hardware/software to the universal compatibility center.
bind
just a man
Authority Member
****
Offline Offline

Posts: 593


« Reply #6 on: July 25, 2008, 01:37:52 PM »

In SMTP, \n.\n means end of message.

never coded it like that before .. i thought that would be \r\n.\r\n

i must be honest I havent used php for smtp in a long time, but this is how I would have coded that line:

Code:
fputs($smtpConnect, "To: $to\r\nFrom: $from\r\nSubject: $subject\r\n$headers\r\n\r\n$message\r\n.\r\n");

I havent tested it or anything yet ... just  from viewing ... no idea if thats even the cause of the problem ... i'll test it out later and post back if no one posts a solution
« Last Edit: July 25, 2008, 01:50:10 PM by bind » Logged

"... if you give a man a fish, he eats today ... if you teach a man to fish, he eats for the rest of his life ..."

That means I am not here to do your work for you, but to assist you in learning how to code what you need. If you want someone to code for you, hire someone to do it or use an out of the box app. All unsolicited pm's are deleted without reading.
inp o҉rtb
The Gangsta
Global Moderator
Official 110mb Guru
*****
Offline Offline

Posts: 9785

experimental theologian


WWW
« Reply #7 on: July 25, 2008, 01:49:11 PM »

In SMTP, \n.\n means end of message.
never coded it like that before .. i thought that would be \r\n.\r\n

That makes sense. I haven't used SMTP for a while as well.
Logged


blog | my work @ deviantART | please add your hardware/software to the universal compatibility center.
uberwalla
Python Expert
Hyper-Active Member
***
Offline Offline

Posts: 423


WWW
« Reply #8 on: July 25, 2008, 02:08:59 PM »

The cause of the problem I think is the RCPT TO line because the next message the server gives is RCPT First, and the error comes from the RCPT's return.
Logged

D3xt3r
"Give me the place to stand, and I shall move the Earth"
Global Moderator
Loyal 110MB Member
*****
Offline Offline

Posts: 2798


/root/D/3/X/T/3/R


WWW
« Reply #9 on: July 25, 2008, 09:47:04 PM »

@Bind

\r\n Are Windows carriage returns.

\n Are Linux carriage returns.

However almost all standard systems are equipped to handle both. As should all script made should handle both, and either convert to one or the other.
Logged




I am not taking project requests at the moment...
I have my own projects and work, please do not request, thank you...
bind
just a man
Authority Member
****
Offline Offline

Posts: 593


« Reply #10 on: July 26, 2008, 04:20:40 AM »

@Bind

\r\n Are Windows carriage returns.

\n Are Linux carriage returns.

However almost all standard systems are equipped to handle both. As should all script made should handle both, and either convert to one or the other.

while you would be correct in terms of handling file content at the httpd server level, you are incorrect in terms of the RFC-821 smtp protocol eol (end-of-line) requirements.

You see the communication has nothing to do with manipulation of file data. In fact no "file" is involved at all on the httpd server level, but instead a socket stream connection is made to the SMTP Server, which has nothing to do with a httpd server nor operating system its  run on.

\r is indeed a carriage return.

\n however, is not a carriage return, but actually a line feed.

collectively known as <CRLF> in RFC-821.

as described in http://www.ietf.org/rfc/rfc0821.txt, the world-wide accepted smtp standard all "standard (smtp mail transport) systems" adhere to, both /r/n are a requirements for the protocol in eol syntax.

some email system may be designed or altered to allow transport through them with less stringent eol syntax, but that isnt the norm, and las little to do with operating system involved, unlike file content handling.


@uberwalla,

according to RFC-821:

Quote from: RFC-821

            RCPT <SP> TO:<forward-path> <CRLF>

         This command gives a forward-path identifying one recipient.
         If accepted, the receiver-SMTP returns a 250 OK reply, and
         stores the forward-path.  If the recipient is unknown the
         receiver-SMTP returns a 550 Failure reply.  This second step of
         the procedure can be repeated any number of times.

         The <forward-path> can contain more than just a mailbox.  The
         <forward-path> is a source routing list of hosts and the
         destination mailbox.  The first host in the <forward-path>
         should be the host receiving this command.




ensure the first host listed in the RCPT line is the host recieving the the command, regardless of who the actual recipient is, so in this case, gmail.

EDIT: typos
« Last Edit: July 26, 2008, 10:24:02 PM by bind » Logged

"... if you give a man a fish, he eats today ... if you teach a man to fish, he eats for the rest of his life ..."

That means I am not here to do your work for you, but to assist you in learning how to code what you need. If you want someone to code for you, hire someone to do it or use an out of the box app. All unsolicited pm's are deleted without reading.
uberwalla
Python Expert
Hyper-Active Member
***
Offline Offline

Posts: 423


WWW
« Reply #11 on: July 26, 2008, 05:06:06 AM »

what exactly do you mean, make sure gmail is in it? The email has to be a gmail one? because I've been attempting to send the emails to my main gmail account, from a different gmail.
Logged

bind
just a man
Authority Member
****
Offline Offline

Posts: 593


« Reply #12 on: July 26, 2008, 08:02:47 PM »

ok I finally got some time to work on this.

there were 2 problems in your syntax.

Problem 1:

RCPT TO requires angle brackets (chevrons, greather_than/less_than) be used:

Code:
RCPT TO:<user@domain.com>\r\n

this is a MUST, which is why you are getting the '555 5.5.2 Syntax error in RCPT TO.

your script needs to add those chevrons to be RFC-821 compliant and accepted by the gmail server.

Problem 2:

you were already told about the eol (end-of-line) charactors not being correct.

that was the problem in the line i fixed in my previous post .. apparently you didnt try them together or you would have had a working script.

it wasnt the fact that the script wouldnt load ... it loaded fine at runtime, but the server was choking on the lack of properly formatted eol's (<CRLF> = /r/n) and addition of the chevrons combined, so it appeared that it wouldnt load and jsut took forever until we finally go 2 warnings (php) ... a connection reset by peer warning and a broken-pipe warning.

very strange behaviour from the gmail server I must say, considering it DIDNT choke on the lack of proper eol's when the RCPT was IMPROPERLY formatted WITHOUT the chevrons !!!

every RFC-821 compliant standard smtp email MUST have those proper eol's and chevrons !

when making both the above changes, the following script works:

Code:
<?php
function smtp($from, $namefrom, $to, $nameto, $subject, $message) {
$username = "-removed-";
$password = "-removed-";
$newLine = "\r\n";

$smtpConnect = fsockopen("ssl://smtp.gmail.com:465", 25, $errno, $errstr, 15);
$smtpResponse = fgets($smtpConnect, 515);

if($smtpConnect) {
$logArray['connect'] = $smtpResponse;
}

fputs($smtpConnect, "HELO localhost" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['helo'] = $smtpResponse;

fputs($smtpConnect,"AUTH LOGIN" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['auth'] = $smtpResponse;

fputs($smtpConnect, base64_encode($username) . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['user'] = $smtpResponse;

fputs($smtpConnect, base64_encode($password) . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['pass'] = $smtpResponse;

fputs($smtpConnect, "MAIL FROM: <$from>" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['from'] = $smtpResponse;

fputs($smtpConnect, "RCPT TO: <$to>" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['to'] = $smtpResponse;

fputs($smtpConnect, "DATA" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['data'] = $smtpResponse;

$headers  = "MIME-Version: 1.0" . $newLine;
$headers .= "Content-type: text/plain; charset=iso-8859-1" . $newLine;
$headers .= "To: $nameto <$to>" . $newLine;
$headers .= "From: $namefrom <$from>" . $newLine;

fputs($smtpConnect, "To: $to\r\nFrom: $from\r\nSubject: $subject\r\n$headers\r\n\r\n$message\r\n.\r\n");
$smtpResponse = fgets($smtpConnect, 515);
$logArray['message'] = $smtpResponse;

fputs($smtpConnect, "QUIT" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['quit'] = $smtpResponse;

echo nl2br(var_export($logArray));

}

$to = "-removed-";
$nameto = "-removed-";
$from = "-removed-";
$namefrom = "-removed-";
$subject = "smtp testing 1.2.3.";
$message = "does this work ... yes it does ... yadda yadda yadda";
smtp($from, $namefrom, $to, $nameto, $subject, $message);
print_r($logArray);
?>


with the following server response:

Code:
'connect' => '220 mx.google.com ESMTP y7sm2819351ugc.25 ',
'helo' => '250 mx.google.com at your service ',
'auth' => '334 -removed- ',
'user' => '334 -removed- ',
'pass' => '235 2.7.0 Accepted ',
'from' => '250 2.1.0 OK ',
'to' => '250 2.1.5 OK ',
'data' => '354 Go ahead ',
'message' => '250 2.0.0 OK 1217065987 y7sm2819351ugc.25 ',
'quit' => '221 2.0.0 mx.google.com closing connection y7sm2819351ugc.25

and of course i received the email in my gmail box Wink
« Last Edit: July 26, 2008, 08:14:30 PM by bind » Logged

"... if you give a man a fish, he eats today ... if you teach a man to fish, he eats for the rest of his life ..."

That means I am not here to do your work for you, but to assist you in learning how to code what you need. If you want someone to code for you, hire someone to do it or use an out of the box app. All unsolicited pm's are deleted without reading.
joeyvanhummel
YAY CUSTOM TITLE :D
Hyper-Active Member
***
Online Online

Posts: 270

110MB thanks :D


WWW
« Reply #13 on: July 26, 2008, 08:27:07 PM »

$smtpConnect = fsockopen("ssl://smtp.gmail.com:465", 25, $errno, $errstr, 15);

is wrong

it should be

$smtpConnect = fsockopen("ssl://smtp.gmail.com", 465, $errno, $errstr, 15);

Hope this fixes it
Logged

some siggy this is Sad
bind
just a man
Authority Member
****
Offline Offline

Posts: 593


« Reply #14 on: July 26, 2008, 08:35:14 PM »

no it isnt wrong ... it's jsut different

it works fine either way.

with the port enabled and present in the uri, the system ignores the fsockopen port number.
« Last Edit: July 26, 2008, 08:46:50 PM by bind » Logged

"... if you give a man a fish, he eats today ... if you teach a man to fish, he eats for the rest of his life ..."

That means I am not here to do your work for you, but to assist you in learning how to code what you need. If you want someone to code for you, hire someone to do it or use an out of the box app. All unsolicited pm's are deleted without reading.
joeyvanhummel
YAY CUSTOM TITLE :D
Hyper-Active Member
***
Online Online

Posts: 270

110MB thanks :D


WWW
« Reply #15 on: July 26, 2008, 10:18:52 PM »

no it isnt wrong ... it's jsut different

it works fine either way.

with the port enabled and present in the uri, the system ignores the fsockopen port number.

I didn't know that, sorry, my bad!
Anyway, bind should have solved your problem so i hope it's fixed Cheesy
Logged

some siggy this is Sad
uberwalla
Python Expert
Hyper-Active Member
***
Offline Offline

Posts: 423


WWW
« Reply #16 on: July 27, 2008, 12:54:54 AM »

wow thanks a lot bind.
« Last Edit: July 27, 2008, 12:56:41 AM by uberwalla » Logged

bind
just a man
Authority Member
****
Offline Offline

Posts: 593


« Reply #17 on: July 27, 2008, 12:02:28 PM »

no problem ... glad I could help.

follow the standards and you cant go wrong Wink
Logged

"... if you give a man a fish, he eats today ... if you teach a man to fish, he eats for the rest of his life ..."

That means I am not here to do your work for you, but to assist you in learning how to code what you need. If you want someone to code for you, hire someone to do it or use an out of the box app. All unsolicited pm's are deleted without reading.
Pages: [1]   Go Up
  Send this topic  |  Print  
 
Jump to:  

  Powered by SMF 1.1.5 | SMF © 2006-2008, Simple Machines LLC

Theme by Dilber MC | Using SEO4SMF Mod

All content on this forum (especially posts) is copyright property of 110mb & the member
who wrote the post. So if you wish to steal anyone's post on this forum, you'll wish you
were dead because our lawyers will sue your ass!