phpmailer类实现邮件群发的实例代码

WBOY
Freigeben: 2016-07-25 08:58:29
Original
921 Leute haben es durchsucht
  1. /**

  2. * 邮件群发示例
  3. * phpmailer类应用实例
  4. */
  5. //PHPmailer类 文件
  6. require_once("class.phpmailer.php");
  7. //发送Email函数

  8. function smtp_mail ( $sendto_email, $subject, $body, $extra_hdrs, $user_name) {
  9. $mail = new PHPMailer();
  10. $mail->IsSMTP(); // send via SMTP
  11. $mail->Host = "smtp.163.com"; // SMTP servers
  12. $mail->SMTPAuth = true; // turn on SMTP authentication
  13. $mail->Username = "test123"; // SMTP username 注意:普通邮件认证不需要加 @域名
  14. $mail->Password = "1983106"; // SMTP password
  15. $mail->From = ""; // 发件人邮箱

  16. $mail->FromName = "WWW.JBXUE.COM"; // 发件人 ,比如 程序员之家
  17. $mail->CharSet = "GB2312"; // 这里指定字符集!

  18. $mail->Encoding = "base64";
  19. $mail->AddAddress($sendto_email,$user_name); // 收件人邮箱和姓名

  20. $mail->AddReplyTo("","程序员之家");
  21. //$mail->WordWrap = 50; // set word wrap

  22. //$mail->AddAttachment("/var/tmp/file.tar.gz"); // attachment 附件1
  23. //$mail->AddAttachment("/tmp/image.jpg", "new.jpg"); //附件2
  24. $mail->IsHTML(true); // send as HTML
  25. $mail->Subject = $subject;
  26. // 邮件内容 可以直接发送html文件

  27. $mail->Body =
  28. phpmailer邮件群发示例_bbs.it-home.org
  29. EOT;
  30. $mail->AltBody ="text/html";
  31. if($mail->Send())
  32. {
  33. info_write("ok.txt","$user_name 发送成功");
  34. }
  35. else {
  36. info_write("falied.txt","$user_name 失败,错误信息$mail->ErrorInfo");
  37. }
  38. }
  39. // 发送Email函数结束
  40. // 写入发送结果函数,错误日志记录

  41. function info_write($filename,$info_log)
  42. {
  43. $info.= $info_log;
  44. $info.="\r\n";
  45. $fp = fopen ($filename,a);
  46. fwrite($fp,$info);
  47. fclose($fp);
  48. }
  49. //定时跳转页面 函数 其中 1000是时间,1秒, 您可以自定义

  50. function redirect($url)
  51. {
  52. echo "<script><li>function redirect()<li>{<li>window.location.replace('$url');<li>}<li>window.setTimeout('redirect();', 15000);<li></script>";
  53. }
  54. //读取文本 邮件地址 您也可以读 数据库

  55. $filename = "email.txt";
  56. $fp = fopen($filename,"r");
  57. $contents = fread($fp,filesize($filename));
  58. $list_email=explode("\r\n",$contents);
  59. $len=count($list_email);
  60. fclose($fp);
  61. // 参数说明(发送到, 邮件主题, 邮件内容, 附加信息, 用户名)

  62. $i = $_GET['action'];
  63. $i++;
  64. if ($i{
  65. $rs=explode("@",$list_email[$i]);
  66. $user_name = $rs['0'];
  67. echo "正在发送第{$i}封({$list_email[$i]})邮件......{$user_name}";
  68. smtp_mail($list_email[$i], 'Treasurery Online 周刊第十二期', $body, 'http://bbs.it-home.org/', $user_name);
  69. redirect("?action=$i");
  70. }
  71. else {
  72. echo "邮件全部发送完毕";
  73. exit;
  74. }
  75. ?>
复制代码

代码说明: 以上读取文章email.txt,也可以直接是qq号码,每行一个号码,然后用fget()读取每行qq号码,最后在加上qq邮箱后缀 @qq.com即可。 这个聪明的想法,希望对你有所帮助哈。 附,PHPMailer邮件发送类V5.1下载地址。



Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!