Connecting Tech Pros Worldwide Forums | Help | Site Map

SMTP Error

Newbie
 
Join Date: Oct 2009
Posts: 8
#1: 4 Weeks Ago
I have used smtp mail scripts
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. function authgMail($from, $namefrom, $to, $nameto, $subject, $message) {
  4. $smtpServer = "192.168.xxx.xxx";   //ip address of the mail server.  This can also be the local domain name
  5. $port = "25";                     // should be 25 by default, but needs to be whichever port the mail server will be using for smtp
  6. $timeout = "45";                 // typical timeout. try 45 for slow servers
  7. $username = "sales@mydomain.com"; // the login for your smtp
  8. $password = "myPA$$";            // the password for your smtp
  9. $localhost = "127.0.0.1";       // Defined for the web server.  Since this is where we are gathering the details for the email
  10. $newLine = "\r\n";             // aka, carrage return line feed. var just for newlines in MS
  11. $secure = 0;       
  12. /connect to the host and port
  13. $smtpConnect = fsockopen($smtpServer, $port, $errno, $errstr, $timeout);
  14. $smtpResponse = fgets($smtpConnect, 4096);
  15. if(empty($smtpConnect)) {
  16.    $output = "Failed to connect: $smtpResponse";
  17.    echo $output;
  18.    return $output;
  19. }
  20. else {
  21.    $logArray['connection'] = "<p>Connected to: $smtpResponse";
  22.    echo "<p />connection accepted<br>".$smtpResponse."<p />Continuing<p />";
  23. }
  24.  
  25. //you have to say HELO again after TLS is started
  26.    fputs($smtpConnect, "HELO $localhost". $newLine);
  27.    $smtpResponse = fgets($smtpConnect, 4096);
  28.    $logArray['heloresponse2'] = "$smtpResponse";
  29. //request for auth login
  30. fputs($smtpConnect,"AUTH LOGIN" . $newLine);
  31. $smtpResponse = fgets($smtpConnect, 4096);
  32. $logArray['authrequest'] = "$smtpResponse";
  33.  
  34. //send the username
  35. fputs($smtpConnect, base64_encode($username) . $newLine);
  36. $smtpResponse = fgets($smtpConnect, 4096);
  37. $logArray['authusername'] = "$smtpResponse";
  38.  
  39. //send the password
  40. fputs($smtpConnect, base64_encode($password) . $newLine);
  41. $smtpResponse = fgets($smtpConnect, 4096);
  42. $logArray['authpassword'] = "$smtpResponse";
  43.  
  44. //email from
  45. fputs($smtpConnect, "MAIL FROM: <$from>" . $newLine);
  46. $smtpResponse = fgets($smtpConnect, 4096);
  47. $logArray['mailfromresponse'] = "$smtpResponse";
  48.  
  49. //email to
  50. fputs($smtpConnect, "RCPT TO: <$to>" . $newLine);
  51. $smtpResponse = fgets($smtpConnect, 4096);
  52. $logArray['mailtoresponse'] = "$smtpResponse";
  53.  
  54. //the email
  55. fputs($smtpConnect, "DATA" . $newLine);
  56. $smtpResponse = fgets($smtpConnect, 4096);
  57. $logArray['data1response'] = "$smtpResponse";
  58.  
  59. //construct headers
  60. $headers = "MIME-Version: 1.0" . $newLine;
  61. $headers .= "Content-type: text/html; charset=iso-8859-1" . $newLine;
  62. $headers .= "To: $nameto <$to>" . $newLine;
  63. $headers .= "From: $namefrom <$from>" . $newLine;
  64.  
  65. //observe the . after the newline, it signals the end of message
  66. fputs($smtpConnect, "To: $to\r\nFrom: $from\r\nSubject: $subject\r\n$headers\r\n\r\n$message\r\n.\r\n");
  67. $smtpResponse = fgets($smtpConnect, 4096);
  68. $logArray['data2response'] = "$smtpResponse";
  69.  
  70. // say goodbye
  71. fputs($smtpConnect,"QUIT" . $newLine);
  72. $smtpResponse = fgets($smtpConnect, 4096);
  73. $logArray['quitresponse'] = "$smtpResponse";
  74. $logArray['quitcode'] = substr($smtpResponse,0,3);
  75. fclose($smtpConnect);
  76. //a return value of 221 in $retVal["quitcode"] is a success
  77. return($logArray);
  78. }
  79.  
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
#2: 4 Weeks Ago

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
#3: 4 Weeks Ago

re: SMTP Error


Quote:

Originally Posted by Sajeena View Post

I have used smtp mail scripts

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. function authgMail($from, $namefrom, $to, $nameto, $subject, $message) {
  4. $smtpServer = "192.168.xxx.xxx";   //ip address of the mail server.  This can also be the local domain name
  5. $port = "25";                     // should be 25 by default, but needs to be whichever port the mail server will be using for smtp
  6. $timeout = "45";                 // typical timeout. try 45 for slow servers
  7. $username = "sales@mydomain.com"; // the login for your smtp
  8. $password = "myPA$$";            // the password for your smtp
  9. $localhost = "127.0.0.1";       // Defined for the web server.  Since this is where we are gathering the details for the email
  10. $newLine = "\r\n";             // aka, carrage return line feed. var just for newlines in MS
  11. $secure = 0;       
  12. /connect to the host and port
  13. $smtpConnect = fsockopen($smtpServer, $port, $errno, $errstr, $timeout);
  14. $smtpResponse = fgets($smtpConnect, 4096);
  15. if(empty($smtpConnect)) {
  16.    $output = "Failed to connect: $smtpResponse";
  17.    echo $output;
  18.    return $output;
  19. }
  20. else {
  21.    $logArray['connection'] = "<p>Connected to: $smtpResponse";
  22.    echo "<p />connection accepted<br>".$smtpResponse."<p />Continuing<p />";
  23. }
  24.  
  25. //you have to say HELO again after TLS is started
  26.    fputs($smtpConnect, "HELO $localhost". $newLine);
  27.    $smtpResponse = fgets($smtpConnect, 4096);
  28.    $logArray['heloresponse2'] = "$smtpResponse";
  29. //request for auth login
  30. fputs($smtpConnect,"AUTH LOGIN" . $newLine);
  31. $smtpResponse = fgets($smtpConnect, 4096);
  32. $logArray['authrequest'] = "$smtpResponse";
  33.  
  34. //send the username
  35. fputs($smtpConnect, base64_encode($username) . $newLine);
  36. $smtpResponse = fgets($smtpConnect, 4096);
  37. $logArray['authusername'] = "$smtpResponse";
  38.  
  39. //send the password
  40. fputs($smtpConnect, base64_encode($password) . $newLine);
  41. $smtpResponse = fgets($smtpConnect, 4096);
  42. $logArray['authpassword'] = "$smtpResponse";
  43.  
  44. //email from
  45. fputs($smtpConnect, "MAIL FROM: <$from>" . $newLine);
  46. $smtpResponse = fgets($smtpConnect, 4096);
  47. $logArray['mailfromresponse'] = "$smtpResponse";
  48.  
  49. //email to
  50. fputs($smtpConnect, "RCPT TO: <$to>" . $newLine);
  51. $smtpResponse = fgets($smtpConnect, 4096);
  52. $logArray['mailtoresponse'] = "$smtpResponse";
  53.  
  54. //the email
  55. fputs($smtpConnect, "DATA" . $newLine);
  56. $smtpResponse = fgets($smtpConnect, 4096);
  57. $logArray['data1response'] = "$smtpResponse";
  58.  
  59. //construct headers
  60. $headers = "MIME-Version: 1.0" . $newLine;
  61. $headers .= "Content-type: text/html; charset=iso-8859-1" . $newLine;
  62. $headers .= "To: $nameto <$to>" . $newLine;
  63. $headers .= "From: $namefrom <$from>" . $newLine;
  64.  
  65. //observe the . after the newline, it signals the end of message
  66. fputs($smtpConnect, "To: $to\r\nFrom: $from\r\nSubject: $subject\r\n$headers\r\n\r\n$message\r\n.\r\n");
  67. $smtpResponse = fgets($smtpConnect, 4096);
  68. $logArray['data2response'] = "$smtpResponse";
  69.  
  70. // say goodbye
  71. fputs($smtpConnect,"QUIT" . $newLine);
  72. $smtpResponse = fgets($smtpConnect, 4096);
  73. $logArray['quitresponse'] = "$smtpResponse";
  74. $logArray['quitcode'] = substr($smtpResponse,0,3);
  75. fclose($smtpConnect);
  76. //a return value of 221 in $retVal["quitcode"] is a success
  77. return($logArray);
  78. }
  79.  
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
#4: 4 Weeks Ago

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!
Reply

Tags
smtp mail