SMTP Script: 500 unrecognized command
HejsaFor 1½ år siden fandt jeg et PHP script, hvor jeg kunne sende mails via min internet udbyders SMTP server (STOFA), istedet for at sætte min egen op.
Det har virket upåklageligt, men jeg er begyndt at få nogle fejl i scriptet og mails bliver ikke længere afsendt.
Som jeg ser der kommer der 2 "500 unrecognized command" som nok er det der er fejlen.
Jeg har forsøgt at finde et svar på nettet men uden held.
Måske er der nogen herinde som kan give en forklaring.
------------ response fra SMTP server -----------
connection accepted
220 mx06.stofanet.dk - StofaNet Mail Server.
Continuing
3....250 mx06.stofanet.dk Hello 563453ef.rev.stofanet.dk [86.52.83.239]
4....503 AUTH command used when not advertised
5....500 unrecognized command
6....500 unrecognized command
7....250 OK
8....250 Accepted
9....354 Enter message, ending with "." on a line by itself
11....250 OK id=1VSmSN-0006Hs-2L
12....221 mx06.stofanet.dk closing connection
Hi Flemming, Bla Bla Bla......
------------ PHP Script -----------
function authgMail($from, $namefrom, $to, $nameto, $subject, $message)
{
// 1.0 Initializing variables
$smtpServer = "mail.stofanet.dk"; // IP address of the mail server. This can also be the local domain name
$port = "25"; // Should be 25 by default, but needs to be whichever port the mail server will be using for smtp
$timeout = "45"; // Typical timeout. try 45 for slow servers
$username = "********"; // The login for your smtp
$password = "********"; // The password for your smtp
$localhost = "127.0.0.1"; // Defined for the web server. Since this is where we are gathering the details for the email
$newLine = "\r\n"; // Aka, carrage return line feed. var just for newlines in MS
$secure = 0; // Change to 1 if your server is running under SSL
// 2.0 Connect to the host and port
$smtpConnect = fsockopen($smtpServer, $port, $errno, $errstr, $timeout);
$smtpResponse = fgets($smtpConnect, 4096);
if(empty($smtpConnect))
{
$output = "Failed to connect: $smtpResponse";
echo $output;
return $output;
}
else
{
$logArray['connection'] = "<p>Connected to: $smtpResponse";
echo "<p />connection accepted<br>".$smtpResponse."<p />Continuing<p />";
}
// 3.0 You have to say HELO again after TLS is started
fputs($smtpConnect, "HELO $localhost". $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['heloresponse2'] = "$smtpResponse";
echo ("3....");
echo ($smtpResponse);
echo "<br/>";
// 4.0 Request for auth login
fputs($smtpConnect,"AUTH LOGIN" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['authrequest'] = "$smtpResponse";
echo ("4....");
echo ($smtpResponse);
echo "<br/>";
// 5.0 Send the username
fputs($smtpConnect, base64_encode($username) . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['authusername'] = "$smtpResponse";
echo ("5....");
echo ($smtpResponse);
echo "<br/>";
// 6.0 Send the password
fputs($smtpConnect, base64_encode($password) . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['authpassword'] = "$smtpResponse";
echo ("6....");
echo ($smtpResponse);
echo "<br/>";
// 7.0 Define e-mail from
fputs($smtpConnect, "MAIL FROM: <$from>" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['mailfromresponse'] = "$smtpResponse";
echo ("7....");
echo ($smtpResponse);
echo "<br/>";
// 8.0 Define e-mail to
fputs($smtpConnect, "RCPT TO: <$to>" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['mailtoresponse'] = "$smtpResponse";
echo ("8....");
echo ($smtpResponse);
echo "<br/>";
// 9.0 Construct e-mail
fputs($smtpConnect, "DATA" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['data1response'] = "$smtpResponse";
echo ("9....");
echo ($smtpResponse);
echo "<br/>";
// 10.0 Construct headers
$headers = "MIME-Version: 1.0" . $newLine;
$headers .= "Content-type: text/html; charset=iso-8859-1" . $newLine;
$headers .= "To: $nameto <$to>" . $newLine;
$headers .= "From: $namefrom <$from>" . $newLine;
// 11.0 Send e-mail - observe the . after the newline, it signals the end of message
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, 4096);
$logArray['data2response'] = "$smtpResponse";
echo ("11....");
echo ($smtpResponse);
echo "<br/>";
// 12.0 Say goodbye
fputs($smtpConnect,"QUIT" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['quitresponse'] = "$smtpResponse";
$logArray['quitcode'] = substr($smtpResponse,0,3);
fclose($smtpConnect);
//a return value of 221 in $retVal["quitcode"] is a success
echo ("12....");
echo ($smtpResponse);
return($logArray);
} // End of function authgMail
