首頁 >後端開發 >php教程 >用pear自備的mail類庫發郵件

用pear自備的mail類庫發郵件

WBOY
WBOY原創
2016-07-25 09:01:131565瀏覽
用pear自带的mail类库发邮件,可以用pear install 命令来安装对应的库
  1. $body = "点我重新生成密码";
  2. sendMail_smtp("xxxxxxxx@qq.com",'测试',$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, //收信地址
  21. 'Subject'=>$mailsubject
  22. );
  23. $mime = new Mail_mime();
  24. //$mime->setTXTBody($text);
  25. //添加附件
  26. //$mime->addHTMLImage('php.gif','image/gif','12345',true);
  27. $mime->_build_params['html_charset'] = "utf-8";//设置编码格式
  28. $mime->_build_params['head_charset'] = "utf-8";//设置编码格式
  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. }
复制代码


陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn