首頁  >  文章  >  後端開發  >  phpmailer 發送郵件類別庫

phpmailer 發送郵件類別庫

WBOY
WBOY原創
2016-07-25 09:11:041129瀏覽
phpmailer 发送邮件类库
  1. header('Content-Type: text/html; charset=utf-8');
  2. require("phpmailer/class.phpmailer.php");
  3. error_reporting(E_ERROR);
  4. function smtp_mail ( $sendto_email, $subject, $body ,$att=array()) {
  5. $mail = new PHPMailer();
  6. $mail->IsSMTP();
  7. $mail->Host = "asdfasdfasdf.com";
  8. $mail->Username = "asdfasdfasdfsd@com.cn";
  9. $mail->Password = "234234234234234";
  10. $mail->FromName = "管理员";
  11. $mail->SMTPAuth = true;
  12. $mail->From = $mail->Username;
  13. $mail->CharSet = "utf-8";
  14. $mail->Encoding = "base64";
  15. $mail->AddAddress($sendto_email);
  16. foreach($att as $key=>$val){
  17. if(!empty($val)){
  18. $mail->AddAttachment($val); //注意要给绝对路径
  19. }
  20. }
  21. $mail->IsHTML(true);
  22. $mail->Subject = $subject;
  23. $mail->Body = $body;
  24. $mail->AltBody ="text/html";
  25. if(!$mail->Send()) {
  26. echo "邮件错误信息: " . $mail->ErrorInfo;
  27. }else{
  28. echo "邮件发送成功!";
  29. }
  30. }
  31. $body = '
  32. 欢迎来到http://www.sdfsadfsfsdf.com

  33. 感谢您注册为本站会员!

  34. ';
  35. // 参数说明(发送地址, 邮件主题, 邮件内容,附件绝对路径)
  36. smtp_mail('2342342342342@qq.com', '欢迎你的到来', $body,array('C:/xampp/htdocs/复件.txt'));
  37. ?>
复制代码


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