The logging I've done shows that the 220 Greeting takes 3 lines, and pushes all the other commands into the wrong position. Does anyone know how to take care of the initial 220 greeting so that I can run the auth commands and send mail again?
Thanks
Array Key: connection; Value: Connected: 220-jin.asmallorange.com ESMTP Exim 4.69 #1 Fri, 09 Sep 2011 17:50:10 -0400 Array Key: authrequest; Value: 220-We do not authorize the use of this system to transport unsolicited, Array Key: authusername; Value: 220 and/or bulk e-mail. Array Key: authpassword; Value: 503 AUTH command used when not advertised Array Key: heloresponse; Value: 500 unrecognized command Array Key: mailfromresponse; Value: 500 unrecognized command Array Key: mailtoresponse; Value: 250 jin.asmallorange.com Hello localhost.localdomain [127.0.0.1] Array Key: bccresponse; Value: 550 Authentication failed Array Key: data1response; Value: Array Key: data2response; Value: Array Key: quitresponse; Value:
function authSendEmail($from, $to, $subject, $message, $mime_boundary, $bccs)
{
//SMTP + SERVER DETAILS
/* * * * CONFIGURATION START * * * */
$smtpServer = "localhost";
$port = "25";
$timeout = "30";
$username = "*********";
$password = "*********";
$localhost = "localhost";
$newLine = "\r\n";
/* * * * CONFIGURATION END * * * * */
//Connect to the host on the specified port
$smtpConnect = fsockopen($smtpServer, $port, $errno, $errstr, $timeout);
$smtpResponse = fgets($smtpConnect, 4096);
if(empty($smtpConnect))
{
$output = "Failed to connect: $smtpResponse" . $newLine;
return $output;
}
else
{
$logArray['connection'] = "Connected: $smtpResponse" . $newLine;
}
//Request Auth Login
fputs($smtpConnect,"AUTH LOGIN" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['authrequest'] = "$smtpResponse";
//Send username
fputs($smtpConnect, base64_encode($username) . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['authusername'] = "$smtpResponse";
//Send password
fputs($smtpConnect, base64_encode($password) . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['authpassword'] = "$smtpResponse";
//Say Hello to SMTP
fputs($smtpConnect, "HELO $localhost" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['heloresponse'] = "$smtpResponse";
//Email From
fputs($smtpConnect, "MAIL FROM: $from" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['mailfromresponse'] = "$smtpResponse";
//Email To
fputs($smtpConnect, "RCPT TO: $to" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['mailtoresponse'] = "$smtpResponse";
if (count($bccs) > 0)
{
foreach ($bccs AS $bcc)
{
fputs($smtpConnect, "RCPT TO: $bcc" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['bccresponse'] = "$smtpResponse";
}
}
//The Email
fputs($smtpConnect, "DATA" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['data1response'] = "$smtpResponse";
//Construct Headers
$headers = "MIME-Version: 1.0" . $newLine;
$headers .= "Return-Path: ". $from."".$newLine;
$headers .= "Reply-To: ". $from."".$newLine;
$headers .= "Date: ".date('r')."".$newLine;
$headers .= "Message-ID: <" . md5(uniqid(time())) . "@*************.org>" . $newLine;
$headers .= "X-Priority: 3" . $newLine;
$headers .= "X-Mailer: PHP" . $newLine;
$headers .= "Content-Type: multipart/alternative;boundary=\"".$mime_boundary."\"" . $newLine;
fputs($smtpConnect, "To: $to\nFrom: $from\nSubject: $subject\n$headers\n\n$message\n.\n");
$smtpResponse = fgets($smtpConnect, 515);
$logArray['data2response'] = "$smtpResponse";
// Say Bye to SMTP
fputs($smtpConnect,"QUIT" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['quitresponse'] = "$smtpResponse";
//logging to find out what is wrong
$this_txt_write = '';
foreach ($logArray as $key => $value) {
$this_txt_write .= "Array Key: $key; Value: $value\n";
}
$myFile = "log_file.txt";
$fh = fopen($myFile, 'a') or die("can't open file");
$stringData = $this_txt_write."\n\nNEXT SET OF DATA\n\n";
fwrite($fh, $stringData);
fclose($fh);
}
Edited by symfiddle, 09 September 2011 - 11:49 PM.
Sign In
Create Account










