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
