Send SMTP emails with PEAR


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. function sendHtmlEmail($recipient, $subject, $html) {
  2. // Need PEAR in include path with installed: Mail, Net_Smtp
  3. $headers = array(
  4. 'From' => 'whateveremail',
  5. 'Reply-To' => 'whateveremail',
  6. 'Cc' => 'whateveremail',
  7. 'MIME-Version' => '1.0',
  8. 'Content-Type' => 'text/html; charset=UTF-8',
  9. 'To' => $recipient,
  10. 'Subject' => $subject,
  11. );
  12. $smtp = Mail::factory('smtp', array (
  13. 'host' => 'smtp.server.whatever',
  14. 'port' => 25,
  15. 'auth' => true,
  16. 'username' => ,
  17. 'password' => )
  18. );
  19.  
  20. $mail = $smtp->send($recipient, $headers, $html);
  21.  
  22. if (PEAR::isError($mail)) {
  23. trigger_error($mail->getMessage(), E_USER_WARNING);
  24. return false;
  25. }
  26. return true;
  27. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.