mail from SMTP authentication script doesn't seem to work

Reply

Join Date: Jan 2005
Posts: 70
Reputation: Diode is on a distinguished road 
Solved Threads: 0
Diode's Avatar
Diode Diode is offline Offline
Junior Poster in Training

mail from SMTP authentication script doesn't seem to work

 
0
  #1
Aug 11th, 2009
Hello,

I found a php function that utlizes smtp authentication to send emails. However, when I tried it, no errors are echoed to the browser, but when I check my inbox, there is no mail from that site. I don't think anybody else is getting them either because I asked my friends to make an account on the site and in the email, I asked them to contact me and forward the email to my personal email address so I would know it worked. Thus far, I have received none.

Here is my function:

  1. /* * * * * * * * * * * * * * SEND EMAIL FUNCTIONS * * * * * * * * * * * * * */
  2. //This will send an email using auth smtp and output a log array
  3. //logArray - connection,
  4.  
  5. function authSendEmail($from, $namefrom, $to, $nameto, $subject, $message)
  6. {
  7. //SMTP + SERVER DETAILS
  8.  
  9. // MAX OF 250 EMAILS SENT PER HOUR THROUGH HOST'S EMAIL SERVICE
  10.  
  11. /* * * * CONFIGURATION START * * * */
  12. $smtpServer = "mail.domain.com";
  13. $port = "25";
  14. $timeout = "30";
  15. $username = "me@me.com";
  16. $password = "password";
  17. $localhost = "localhost";
  18. $newLine = "\r\n";
  19. /* * * * CONFIGURATION END * * * * */
  20.  
  21. //Connect to the host on the specified port
  22. $smtpConnect = fsockopen($smtpServer, $port, $errno, $errstr, $timeout);
  23. $smtpResponse = fgets($smtpConnect, 515);
  24. if(empty($smtpConnect))
  25. {
  26. $output = "Failed to connect: $smtpResponse";
  27. return $output;
  28. }
  29. else
  30. {
  31. $logArray['connection'] = "Connected: $smtpResponse";
  32. }
  33.  
  34. //Request Auth Login
  35. fputs($smtpConnect,"AUTH LOGIN" . $newLine);
  36. $smtpResponse = fgets($smtpConnect, 515);
  37. $logArray['authrequest'] = "$smtpResponse";
  38.  
  39. //Send username
  40. fputs($smtpConnect, base64_encode($username) . $newLine);
  41. $smtpResponse = fgets($smtpConnect, 515);
  42. $logArray['authusername'] = "$smtpResponse";
  43.  
  44. //Send password
  45. fputs($smtpConnect, base64_encode($password) . $newLine);
  46. $smtpResponse = fgets($smtpConnect, 515);
  47. $logArray['authpassword'] = "$smtpResponse";
  48.  
  49. //Say Hello to SMTP
  50. fputs($smtpConnect, "HELO $localhost" . $newLine);
  51. $smtpResponse = fgets($smtpConnect, 515);
  52. $logArray['heloresponse'] = "$smtpResponse";
  53.  
  54. //Email From
  55. fputs($smtpConnect, "MAIL FROM: $from" . $newLine);
  56. $smtpResponse = fgets($smtpConnect, 515);
  57. $logArray['mailfromresponse'] = "$smtpResponse";
  58.  
  59. //Email To
  60. fputs($smtpConnect, "RCPT TO: $to" . $newLine);
  61. $smtpResponse = fgets($smtpConnect, 515);
  62. $logArray['mailtoresponse'] = "$smtpResponse";
  63.  
  64. //The Email
  65. fputs($smtpConnect, "DATA" . $newLine);
  66. $smtpResponse = fgets($smtpConnect, 515);
  67. $logArray['data1response'] = "$smtpResponse";
  68.  
  69. //Construct Headers
  70. $headers = "MIME-Version: 1.0" . $newLine;
  71. $headers .= "Content-type: text/html; charset=iso-8859-1" . $newLine;
  72. $headers .= "To: $nameto <$to>" . $newLine;
  73. $headers .= "From: $namefrom <$from>" . $newLine;
  74.  
  75. fputs($smtpConnect, "To: $to\nFrom: $from\nSubject: $subject\n$headers\n\n$message\n.\n");
  76. $smtpResponse = fgets($smtpConnect, 515);
  77. $logArray['data2response'] = "$smtpResponse";
  78.  
  79. // Say Bye to SMTP
  80. fputs($smtpConnect,"QUIT" . $newLine);
  81. $smtpResponse = fgets($smtpConnect, 515);
  82. $logArray['quitresponse'] = "$smtpResponse";
  83. }

Posting this was my last resort. I have been tangling with this for a week.

Thanks. Any and all help is appreciated.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 142
Reputation: whiteyoh is an unknown quantity at this point 
Solved Threads: 2
whiteyoh whiteyoh is offline Offline
Junior Poster

Re: mail from SMTP authentication script doesn't seem to work

 
0
  #2
Aug 18th, 2009
have you checked that the hosting supports smtp? some dont, i would expect them to though. same goes for the port number.

also, if your at work, and they have an exchange server, you probably wont be allowed to use smtp and may not get a response from the mailserver
Reply With Quote Quick reply to this message  
Join Date: Jan 2005
Posts: 70
Reputation: Diode is on a distinguished road 
Solved Threads: 0
Diode's Avatar
Diode Diode is offline Offline
Junior Poster in Training

Re: mail from SMTP authentication script doesn't seem to work

 
0
  #3
Aug 18th, 2009
Thanks, but I already solved it. I just installed Pear and used that.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 142
Reputation: whiteyoh is an unknown quantity at this point 
Solved Threads: 2
whiteyoh whiteyoh is offline Offline
Junior Poster

Re: mail from SMTP authentication script doesn't seem to work

 
0
  #4
Aug 18th, 2009
nice one
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC