Home > Backend Development > PHP Tutorial > Send emails using pear's own mail library

Send emails using pear's own mail library

WBOY
Release: 2016-07-25 09:01:13
Original
1562 people have browsed it
Use pear's own mail class library to send emails. You can use the pear install command to install the corresponding library.
  1. $body = "Click me to regenerate password";
  2. sendMail_smtp("xxxxxxxx @qq.com",'test',$body);
  3. function sendMail_smtp($smtpemailto,$mailsubject,$mailbody){
  4. //error_reporting(7);
  5. require_once 'Mail.php';
  6. require_once 'Mail /mime.php';
  7. $from = 'admin@xxx.com';
  8. $to = $smtpemailto;
  9. $password = 'xxxxxx';
  10. $mail_config=array(
  11. "host"=>"smtp .ym.163.com",
  12. "port"=>25,
  13. "auth"=>true,
  14. "username"=>$from,
  15. "password"=>$password,
  16. "from" =>$from,
  17. );
  18. $hdrs = array(
  19. 'From'=>$from,
  20. 'To' => $to, //receiving address
  21. 'Subject'=>$mailsubject
  22. );
  23. $mime = new Mail_mime();
  24. //$mime->setTXTBody($text);
  25. //Add attachment
  26. //$mime->addHTMLImage('php.gif','image /gif','12345',true);
  27. $mime->_build_params['html_charset'] = "utf-8";//Set the encoding format
  28. $mime->_build_params['head_charset'] = "utf -8";//Set encoding format
  29. $mime->setHTMLBody($mailbody);
  30. $body = $mime->get();
  31. $hdrs = $mime->headers($hdrs);
  32. $mail = Mail::factory('smtp',$mail_config);
  33. $succ = $mail->send($to,$hdrs,$body);
  34. if (PEAR::isError($succ) )
  35. {
  36. //echo 'Email sending failed: ' . $succ->getMessage();
  37. $err = 'Email sending failed: ' . $succ->getMessage();
  38. $content = $to. "t".date('Y-m-d H:i:s')."t ".$err." rn" ;
  39. }
  40. else
  41. {
  42. //$content = $to."t".date('Y-m-d H:i:s')."t Email sent succesfully rn" ;
  43. return true;
  44. }
  45. }
Copy code


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template