- - - - -

SMTP Email Problem


  • Please log in to reply
6 replies to this topic

#1 symfiddle

symfiddle

    Small Orange

  • Members
  • PipPip
  • 23 posts

Posted 09 September 2011 - 11:48 PM

I've been using a basic SMTP script to send emails.  It's worked for well over a year. Now it's stopped working...

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.


#2 davidatfuzzylime

davidatfuzzylime

    Designer; coder; geek

  • Members
  • PipPipPipPipPip
  • 424 posts

Posted 10 September 2011 - 02:41 AM

As a quick and dirty fix you could probably replace this line:
$logArray['connection'] = "Connected: $smtpResponse" . $newLine;

with this:
$logArray['connection'] = "Connected: $smtpResponse" . $newLine;
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['connection'] .= "$smtpResponse" . $newLine;
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['connection'] .= "$smtpResponse" . $newLine;

Not hugely elegant but it'll deal with those three lines instead of one?
fuzzylime: we know design
Save money when you sign up! Go here then use code giveme15 to get 15% off or giveme5 to get $5 off your order.

#3 symfiddle

symfiddle

    Small Orange

  • Members
  • PipPip
  • 23 posts

Posted 10 September 2011 - 02:52 AM

Yeah, I tried that, and it does the same thing, adds in a 500 error for the two extra connection entries and then moves on to prevent the auth routine from working... I'm wondering if there's some bad characters or extra newlines in the greeting, but that's probably wishful thinking as I can't find a way around this.

Update:  I sent them a test script and now with your code the return looks like this.  Looks like it is expecting TLS, which is why the login is not getting accepted.

Array ( [connection] => Connected: 220-jin.asmallorange.com ESMTP Exim 4.69 #1 Sat, 10 Sep 2011 04:07:42 -0400 220-We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail. [heloresponse] => 250-jin.asmallorange.com Hello localhost.localdomain [127.0.0.1] [authrequest] => 250-SIZE 52428800 [authusername] => 250-PIPELINING [authpassword] => 250-AUTH PLAIN LOGIN [mailfromresponse] => 250-STARTTLS [mailtoresponse] => 250 HELP [bccresponse] => 334 VXNlcm5hbWU6 [data1response] => 334 UGFzc3dvcmQ6 [data2response] => 535 Incorrect authentication data [quitresponse] => 503 sender not yet given )


View Postdavidatfuzzylime, on 10 September 2011 - 02:41 AM, said:

As a quick and dirty fix you could probably replace this line:
$logArray['connection'] = "Connected: $smtpResponse" . $newLine;

with this:
$logArray['connection'] = "Connected: $smtpResponse" . $newLine;
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['connection'] .= "$smtpResponse" . $newLine;
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['connection'] .= "$smtpResponse" . $newLine;

Not hugely elegant but it'll deal with those three lines instead of one?

Edited by symfiddle, 10 September 2011 - 03:18 AM.


#4 davidatfuzzylime

davidatfuzzylime

    Designer; coder; geek

  • Members
  • PipPipPipPipPip
  • 424 posts

Posted 10 September 2011 - 02:54 AM

Ah, sounds like the problem is maybe further up the chain, then. Sorry I can't help, might be one worth contacting the techs about directly.
fuzzylime: we know design
Save money when you sign up! Go here then use code giveme15 to get 15% off or giveme5 to get $5 off your order.

#5 symfiddle

symfiddle

    Small Orange

  • Members
  • PipPip
  • 23 posts

Posted 10 September 2011 - 03:31 AM

View Postdavidatfuzzylime, on 10 September 2011 - 02:54 AM, said:

Ah, sounds like the problem is maybe further up the chain, then. Sorry I can't help, might be one worth contacting the techs about directly.

That's what I did, and Antun K sent me a script that works.  Now I need to add a few things to it without breaking it...

Thanks Antun

#6 IBBoard

IBBoard

    Massive Orange

  • Volunteer Moderators
  • PipPipPipPipPipPipPip
  • 4,729 posts

Posted 12 September 2011 - 02:22 PM

Any chance you can post the script (or the differences between that and what you have) so that others can benefit?
The more information you provide, the better answer the community can give.

*** Sign up at ASO  with a 15% discount (coupon: saveme15%) or $5 discount (coupon: saveme$5) ***
(Valid on shared hosting and VPS)

#7 symfiddle

symfiddle

    Small Orange

  • Members
  • PipPip
  • 23 posts

Posted 12 September 2011 - 02:40 PM

View PostIBBoard, on 12 September 2011 - 02:22 PM, said:

Any chance you can post the script (or the differences between that and what you have) so that others can benefit?

I would, but it's not my script, so not my call.  But I'm sure tech support will give you a copy.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users