SMTP Error | Newbie | | Join Date: Oct 2009
Posts: 8
| |
I have used smtp mail scripts - <?php
-
-
function authgMail($from, $namefrom, $to, $nameto, $subject, $message) {
-
$smtpServer = "192.168.xxx.xxx"; //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 = "sales@mydomain.com"; // the login for your smtp
-
$password = "myPA$$"; // 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;
-
/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 />";
-
}
-
-
//you have to say HELO again after TLS is started
-
fputs($smtpConnect, "HELO $localhost". $newLine);
-
$smtpResponse = fgets($smtpConnect, 4096);
-
$logArray['heloresponse2'] = "$smtpResponse";
-
//request for auth login
-
fputs($smtpConnect,"AUTH LOGIN" . $newLine);
-
$smtpResponse = fgets($smtpConnect, 4096);
-
$logArray['authrequest'] = "$smtpResponse";
-
-
//send the username
-
fputs($smtpConnect, base64_encode($username) . $newLine);
-
$smtpResponse = fgets($smtpConnect, 4096);
-
$logArray['authusername'] = "$smtpResponse";
-
-
//send the password
-
fputs($smtpConnect, base64_encode($password) . $newLine);
-
$smtpResponse = fgets($smtpConnect, 4096);
-
$logArray['authpassword'] = "$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";
-
-
//the email
-
fputs($smtpConnect, "DATA" . $newLine);
-
$smtpResponse = fgets($smtpConnect, 4096);
-
$logArray['data1response'] = "$smtpResponse";
-
-
//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;
-
-
//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";
-
-
// 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
-
return($logArray);
-
}
-
This is one of the code i got from one of the site.But when i tried i am getting $logArray['quitcode'] -"354" and no email is receiving.Please Help
| | Member | | Join Date: Oct 2006 Location: Netherlands
Posts: 92
| | | re: SMTP Error
Hmm, i had a problem before with the mail system.
Afterwards it was the $newline that was causing the problem.
Depends on the mailserver your script is running on.
with my script i changed the $newline = "\r\n"; with $newline = "\n";
After that it worked again and hope for you to! :)
Gr paul
| | Newbie | | Join Date: Oct 2009
Posts: 8
| | | re: SMTP Error Quote:
Originally Posted by Sajeena I have used smtp mail scripts - <?php
-
-
function authgMail($from, $namefrom, $to, $nameto, $subject, $message) {
-
$smtpServer = "192.168.xxx.xxx"; //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 = "sales@mydomain.com"; // the login for your smtp
-
$password = "myPA$$"; // 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;
-
/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 />";
-
}
-
-
//you have to say HELO again after TLS is started
-
fputs($smtpConnect, "HELO $localhost". $newLine);
-
$smtpResponse = fgets($smtpConnect, 4096);
-
$logArray['heloresponse2'] = "$smtpResponse";
-
//request for auth login
-
fputs($smtpConnect,"AUTH LOGIN" . $newLine);
-
$smtpResponse = fgets($smtpConnect, 4096);
-
$logArray['authrequest'] = "$smtpResponse";
-
-
//send the username
-
fputs($smtpConnect, base64_encode($username) . $newLine);
-
$smtpResponse = fgets($smtpConnect, 4096);
-
$logArray['authusername'] = "$smtpResponse";
-
-
//send the password
-
fputs($smtpConnect, base64_encode($password) . $newLine);
-
$smtpResponse = fgets($smtpConnect, 4096);
-
$logArray['authpassword'] = "$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";
-
-
//the email
-
fputs($smtpConnect, "DATA" . $newLine);
-
$smtpResponse = fgets($smtpConnect, 4096);
-
$logArray['data1response'] = "$smtpResponse";
-
-
//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;
-
-
//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";
-
-
// 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
-
return($logArray);
-
}
-
This is one of the code i got from one of the site.But when i tried i am getting $logArray['quitcode'] -"354" and no email is receiving.Please Help Hello,
I tried by replacing "\r\n" with "\n",but the same result :(
I am getting
[data2response] => 250 Accepted
[quitresponse] => 354
[quitcode] => 354
| | Member | | Join Date: Oct 2006 Location: Netherlands
Posts: 92
| | | re: SMTP Error
Hmm, then it must be something like this:
Reply codes in numerical order Code Meaning
200 (nonstandard success response, see rfc876)
211 System status, or system help reply
214 Help message
220 <domain> Service ready
221 <domain> Service closing transmission channel
250 Requested mail action okay, completed
251 User not local; will forward to <forward-path>
354 Start mail input; end with <CRLF>.<CRLF>
421 <domain> Service not available, closing transmission channel
It's a smtp errorcode which you can find.
Maybe this will help you further..
Cheers!
|  | | | | Forums
Visit our community forums for general discussions and latest on Bytes
/bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,561 network members.
|