|
uberwalla
|
 |
« 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: <?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: '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
|
 |
« 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 
|
|
|
|
|
Logged
|
|
|
|
|
RBCFAQS
|
 |
« Reply #2 on: July 25, 2008, 07:57:34 AM » |
|
|
|
|
|
|
Logged
|
|
|
|
|
uberwalla
|
 |
« 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
|
 |
« Reply #4 on: July 25, 2008, 12:43:23 PM » |
|
are you sure this line is correct ? 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
|
Learn the basics, create your code, then post source code to troublshoot if you have any problems Here is all you need to learn the basics HTMLJavascriptCSSPHPMySQL.
|
|
|
inp o҉rtb
The Gangsta
Global Moderator
Official 110mb Guru
   
Online
Posts: 11979
experimental theologian
|
 |
« Reply #5 on: July 25, 2008, 01:12:24 PM » |
|
In SMTP, \n.\n means end of message.
|
|
|
|
|
Logged
|
|
|
|
|
bind
|
 |
« 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: 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
|
Learn the basics, create your code, then post source code to troublshoot if you have any problems Here is all you need to learn the basics HTMLJavascriptCSSPHPMySQL.
|
|
|
inp o҉rtb
The Gangsta
Global Moderator
Official 110mb Guru
   
Online
Posts: 11979
experimental theologian
|
 |
« 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
|
|
|
|
|
uberwalla
|
 |
« 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
Guest
|
 |
« 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
|
|
|
|
|
bind
|
 |
« 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: 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
|
Learn the basics, create your code, then post source code to troublshoot if you have any problems Here is all you need to learn the basics HTMLJavascriptCSSPHPMySQL.
|
|
|
|
uberwalla
|
 |
« 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
|
 |
« 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: 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: <?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: '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 
|
|
|
|
« Last Edit: July 26, 2008, 08:14:30 PM by bind »
|
Logged
|
Learn the basics, create your code, then post source code to troublshoot if you have any problems Here is all you need to learn the basics HTMLJavascriptCSSPHPMySQL.
|
|
|
Joey van Hummel
A banana!
Authority Member
  
Offline
Posts: 811
(slowly but surely)Re-writing Age-Script...
|
 |
« 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
|
 Currently rewriting agescript. to do: admin area, setup, image viewer, login, registering, profile editing, newsletter emailer, image uploader(follows 110mb TOS), styles, CSS website, banning system, bad words filter
|
|
|
|
bind
|
 |
« 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
|
Learn the basics, create your code, then post source code to troublshoot if you have any problems Here is all you need to learn the basics HTMLJavascriptCSSPHPMySQL.
|
|
|
Joey van Hummel
A banana!
Authority Member
  
Offline
Posts: 811
(slowly but surely)Re-writing Age-Script...
|
 |
« 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 
|
|
|
|
|
Logged
|
 Currently rewriting agescript. to do: admin area, setup, image viewer, login, registering, profile editing, newsletter emailer, image uploader(follows 110mb TOS), styles, CSS website, banning system, bad words filter
|
|
|
|
uberwalla
|
 |
« 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
|
 |
« Reply #17 on: July 27, 2008, 12:02:28 PM » |
|
no problem ... glad I could help. follow the standards and you cant go wrong 
|
|
|
|
|
Logged
|
Learn the basics, create your code, then post source code to troublshoot if you have any problems Here is all you need to learn the basics HTMLJavascriptCSSPHPMySQL.
|
|
|
|