943,169 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 367
  • PHP RSS
Aug 30th, 2010
0

send html email

Expand Post »
I know I am probably missing something small but I can't seem to get it running

I need to send an html email for newsletters and on registration
But it needs to be authorised so it doesn't get marked as spam or filtered.

here is what I have so far:

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

and for sending an email

PHP Syntax (Toggle Plain Text)
  1. $to = "$email";
  2. $nameto = "$fname $lname";
  3. $from = "email@example.com";
  4. $namefrom = "my name";
  5. $subject = "subject";
  6. $message = "Hi $fname.<br /><br />message stuff here";
  7. authSendEmail($from, $namefrom, $to, $nameto, $subject, $message);
Similar Threads
Reputation Points: 13
Solved Threads: 34
Posting Whiz in Training
metalix is offline Offline
218 posts
since Mar 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: need a way to add a multi-selection box to an update form
Next Thread in PHP Forum Timeline: How to send reminder emails to users every 6 months?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC