当前位置:Gxlcms > PHP教程 > phpmailer发送邮件类库

phpmailer发送邮件类库

时间:2021-07-01 10:21:17 帮助过:16人阅读

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. ?>

人气教程排行