国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > PHP > 正文

PHP郵件群發機實現代碼

2020-03-22 19:22:33
字體:
來源:轉載
供稿:網友
原理:
第一:申請大量的郵箱帳號 騰訊的 126的 163的 新浪的 雅虎的 谷歌的 等等提供smtp服務的
第二:收集你要發送郵件的郵件列表
第三:遍歷郵件列表,每一個郵件發送郵件
第四:用linux下定時腳本后臺運行 我跑了兩天 哈哈 ,因為為了盡可能的保證每一個都發送成功
原理是很簡單,但是其中還是遇到很多的問題。
第一:郵件失敗的問題,我這里采用兩個方式解決,第一把大量的那些郵箱帳號依次去發送,直到成功。然后每次發送500封郵件 后把發送郵箱列表隨機打散(避免一個持續失敗)。
我用的是phpmailer
多的不多說了上代碼了。phpmailer 大家自己搜索下載吧
入口腳本:就是linux 執行的 mail_001.php
php define('ROOT_PATH',dirname(__FILE__)); require_once 'library/senderApi.php'; //發送郵件接口 require_once 'config/senderListConf.php'; //發送郵件帳號列表 //讀取文本 郵件地址 shuffle($senderListConf); $filename = "data/email.txt"; $fp = fopen($filename,"r"); $contents = fread($fp,filesize($filename)); $list_email=explode("/r/n",$contents); $len=count($list_email); fclose($fp); //郵件內容為網頁上的內容 $htmlContent = file_get_contents('http://taobao.1080www.com'); // 參數說明(發送到, 郵件主題, 郵件內容, 附加信息, 用戶名) foreach($list_email as $key= $value) $value = trim($value); $rs=explode("@",$value); $user_name = $rs['0']; smtp_mail($value, '秋季補水化妝品_秋季護膚皮膚保養_秋天皮膚干燥怎么辦-小常識',$htmlContent, 'http://taobao.1080www.com/', $user_name,$senderListConf,0); sleep(3); if($key%200 == 0 && $key 0) shuffle($senderListConf); //每200次 吧發送郵件順序打亂一次 die('SendingOver.................'."/r/n");
封裝phpmailer senderApi.php
php // 請求 PHPmailer類 文件 error_reporting(E_ERROR); require_once("phpmailer/phpmailer.class.php"); // 寫入發送結果函數 function info_write($filename,$info_log) $info.= $info_log; $info.="/r/n"; $fp = fopen ($filename,'a'); fwrite($fp,$info); fclose($fp); //發送Email函數 function smtp_mail ( $sendto_email, $subject, $body, $extra_hdrs, $user_name,$senderListConf,$sender=0) { $batch_no = date("Y_m_d_H"); $mail = new PHPMailer(); $mail- IsSMTP(); $sender_info = $senderListConf[$sender]; if(!$sender_info) 'die 發送帳號出錯了..............'; // send via SMTP $mail- Host = $sender_info['Host']; // SMTP servers $mail- SMTPAuth = true; // turn on SMTP authentication $mail- Username = $sender_info['Username']; // SMTP username 注意:普通郵件認證不需要加 @域名 $mail- Password = $sender_info['Password']; // SMTP password $mail- From = $sender_info['Username']; // 發件人郵箱 $mail- FromName = "淘寶推薦---TaoBao"; // 發件人 ,比如 中國資金管理網 $mail- CharSet = "UTF-8"; // 這里指定字符集! $mail- Encoding = "base64"; $mail- AddAddress($sendto_email,$user_name); // 收件人郵箱和姓名 $mail- AddReplyTo("ken@cscsws.com","淘寶推薦"); //$mail- WordWrap = 50; // set word wrap //$mail- AddAttachment("/var/tmp/file.tar.gz"); // attachment 附件1 //$mail- AddAttachment("/home/www/images/zhuanti/qiujibushui/qiujibushui_attache.jpg", "new.jpg"); //附件2 $mail- IsHTML(true); // send as HTML $mail- Subject = $subject; // 郵件內容 可以直接發送html文件 $mail- Body = $body; $mail- AltBody ="text/html"; if($mail- Send()) info_write(ROOT_PATH.'/log/'.$batch_no."ok.txt","$user_name 發送成功"); else info_write(ROOT_PATH.'/log/'.$batch_no."falied.txt","$user_name 失敗,發送賬號".$sender_info['Username'].",錯誤信息$mail- ErrorInfo"); if($senderListConf[$sender+1]) $sender = smtp_mail ( $sendto_email, $subject, $body, $extra_hdrs, $user_name,$senderListConf,($sender+1)); return $sender; }
發送郵件列表示例 senderListConf.php
php $senderListConf = array( //搜狐郵箱 array('Host'= 'smtp.sohu.com','Username'= 'youemail@sohu.com','Password'= 'yourpassword'), //雅虎郵箱 array('Host'= 'smtp.mail.yahoo.com','Username'= 'youemail@yahoo.cn','Password'= 'yourpassword'), //163郵箱 array('Host'= 'smtp.163.com','Username'= 'youemail@163.com','Password'= 'yourpassword'), //126郵箱 array('Host'= 'smtp.126.com','Username'= 'youemail@126.com','Password'= 'yourpassword'), //qq郵箱 array('Host'= 'smtp.qq.com','Username'= 'youemail@qq.com','Password'= 'yourpassword'), //谷歌郵箱 array('Host'= 'smtp.gmail.com','Username'= 'youemail@gmail.com','Password'= 'yourpassword'), //139郵箱 array('Host'= 'smtp.139.com','Username'= 'youemail@139.com','Password'= 'yourpassword'), //qq郵箱 array('Host'= 'smtp.qq.com','Username'= 'youemail@qq.com','Password'= '(yourpassword'), );PHP教程

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 内丘县| 漠河县| 遵义市| 湖北省| 滦平县| 彩票| 姚安县| 淮滨县| 肃南| 睢宁县| 柘城县| 孝昌县| 竹溪县| 武鸣县| 句容市| 桐乡市| 河间市| 铜川市| 嘉义县| 壤塘县| 宜丰县| 盐山县| 名山县| 方山县| 宁陕县| 繁峙县| 乌什县| 绥化市| 和硕县| 满城县| 江西省| 柯坪县| 铁岭市| 舒兰市| 大同市| 普兰县| 靖远县| 关岭| 阳新县| 永昌县| 焉耆|