php通過讀取文本進行郵件群發的程式

來源:互聯網
上載者:User
  1. // 請求 PHPmailer類 檔案

  2. require_once("class.phpmailer.php");

  3. //發送Email函數

  4. function smtp_mail ( $sendto_email, $subject, $body, $extra_hdrs, $user_name) {
  5. $mail = new PHPMailer();
  6. $mail->IsSMTP(); // send via SMTP
  7. $mail->Host = "smtp.163.com"; // SMTP servers
  8. $mail->SMTPAuth = true; // turn on SMTP authentication
  9. $mail->Username = "jessiejl"; // SMTP username 注意:普通郵件認證不需要加 @網域名稱
  10. $mail->Password = "1983106"; // SMTP password

  11. $mail->From = ""; // 寄件者郵箱

  12. $mail->FromName = bbs.it-home.org; // 寄件者 ,指令碼學堂
  13. $mail->CharSet = "GB2312"; // 這裡指定字元集!
  14. $mail->Encoding = "base64";

  15. $mail->AddAddress($sendto_email,$user_name);// 收件者郵箱和姓名

  16. $mail->AddReplyTo("","中國資金管理網");

  17. //$mail->WordWrap = 50; // set word wrap

  18. //$mail->AddAttachment("/var/tmp/file.tar.gz");// attachment 附件1
  19. //$mail->AddAttachment("/tmp/image.jpg", "new.jpg"); //附件2
  20. $mail->IsHTML(true); // send as HTML
  21. $mail->Subject = $subject;

  22. // 郵件內容 可以直接發送html檔案

  23. $mail->Body = <<
  24. Treasurery Online 周刊
  25. EOT;
  26. $mail->AltBody ="text/html";
  27. if($mail->Send())
  28. {
  29. info_write("ok.txt","$user_name 發送成功");
  30. }
  31. else {
  32. info_write("falied.txt","$user_name 失敗,錯誤資訊$mail->ErrorInfo");
  33. }
  34. }
  35. // 發送Email函數結束

  36. // 寫入發送結果函數,錯誤記錄檔記錄

  37. function info_write($filename,$info_log)
  38. {
  39. $info.= $info_log;
  40. $info.="\r\n";
  41. $fp = fopen ($filename,a);
  42. fwrite($fp,$info);
  43. fclose($fp);
  44. }

  45. //定時跳轉頁面 函數其中 1000是時間,1秒, 您可以自訂

  46. function redirect($url)
  47. {
  48. echo "";
  49. }

  50. //讀取文本 郵件地址 您也可以讀 資料庫

  51. $filename = "email.txt";
  52. $fp = fopen($filename,"r");
  53. $contents = fread($fp,filesize($filename));
  54. $list_email=explode("\r\n",$contents);
  55. $len=count($list_email);
  56. fclose($fp);

  57. // 參數說明(發送到, 郵件主題, 郵件內容, 附加資訊, 使用者名稱)

  58. $i = $_GET['action'];
  59. $i++;
  60. if ($i<$len)
  61. {
  62. $rs=explode("@",$list_email[$i]);
  63. $user_name = $rs['0'];
  64. echo "正在發送第{$i}封({$list_email[$i]})郵件......{$user_name}";
  65. smtp_mail($list_email[$i], 'Treasurery Online 周刊第十二期', $body, 'http://bbs.it-home.org/', $user_name);
  66. redirect("?action=$i");
  67. }
  68. else {
  69. echo "郵件全部發送完畢";
  70. exit;
  71. }
  72. ?>
複製代碼

說明:讀取文章email.txt,也可以直接是qq號碼,每行一個號碼,然後用fget()讀取每行qq號碼,最後在加上qq郵箱尾碼@qq.com即可,其實php郵件群發很簡單,因公司需要PHP群發郵件,所以最近在做一個PHP群發程式系統,可以自由自設定多個群發郵箱,這樣群發數量就有保證了,所有設定都案頭化,很直觀操作!上面的PHP群發郵件,一次群發郵件數量測試在100-200之間且在本地群發即可無需上傳網上空間!

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.