PHP郵件群發(fā)機(jī)實(shí)現(xiàn)代碼
原理:
第一:申請(qǐng)大量的郵箱帳號(hào) 騰訊的 126的 163的 新浪的 雅虎的 谷歌的 等等提供smtp服務(wù)的
第二:收集你要發(fā)送郵件的郵件列表
第三:遍歷郵件列表,每一個(gè)郵件發(fā)送郵件
第四:用linux下定時(shí)腳本后臺(tái)運(yùn)行 我跑了兩天 哈哈 ,因?yàn)闉榱吮M可能的保證每一個(gè)都發(fā)送成功
原理是很簡(jiǎn)單,但是其中還是遇到很多的問(wèn)題。
第一:郵件失敗的問(wèn)題,我這里采用兩個(gè)方式解決,第一把大量的那些郵箱帳號(hào)依次去發(fā)送,直到成功。然后每次發(fā)送500封郵件 后把發(fā)送郵箱列表隨機(jī)打散(避免一個(gè)持續(xù)失?。?。
我用的是phpmailer
多的不多說(shuō)了上代碼了。phpmailer 大家自己搜索下載吧
入口腳本:就是linux 執(zhí)行的 mail_001.php
<?php define('ROOT_PATH',dirname(__FILE__)); require_once 'library/senderApi.php'; //發(fā)送郵件接口 require_once 'config/senderListConf.php'; //發(fā)送郵件帳號(hào)列表 //讀取文本 郵件地址 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); //郵件內(nèi)容為網(wǎng)頁(yè)上的內(nèi)容 $htmlContent = file_get_contents('http://taobao.1080www.com'); // 參數(shù)說(shuō)明(發(fā)送到, 郵件主題, 郵件內(nèi)容, 附加信息, 用戶名) foreach($list_email as $key=>$value) { $value = trim($value); $rs=explode("@",$value); $user_name = $rs['0']; smtp_mail($value, '秋季補(bǔ)水化妝品_秋季護(hù)膚皮膚保養(yǎng)_秋天皮膚干燥怎么辦-小常識(shí)',$htmlContent, 'http://taobao.1080www.com/', $user_name,$senderListConf,0); sleep(3); if($key%200 == 0 && $key>0) { shuffle($senderListConf); //每200次 吧發(fā)送郵件順序打亂一次 } } die('SendingOver.................'."\r\n"); ?>
封裝phpmailer senderApi.php
<?php // 請(qǐng)求 PHPmailer類 文件 error_reporting(E_ERROR); require_once("phpmailer/phpmailer.class.php"); // 寫入發(fā)送結(jié)果函數(shù) function info_write($filename,$info_log) { $info.= $info_log; $info.="\r\n"; $fp = fopen ($filename,'a'); fwrite($fp,$info); fclose($fp); } //發(fā)送Email函數(shù) 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 發(fā)送帳號(hào)出錯(cuò)了..............'; // send via SMTP $mail->Host = $sender_info['Host']; // SMTP servers $mail->SMTPAuth = true; // turn on SMTP authentication $mail->Username = $sender_info['Username']; // SMTP username 注意:普通郵件認(rèn)證不需要加 @域名 $mail->Password = $sender_info['Password']; // SMTP password $mail->From = $sender_info['Username']; // 發(fā)件人郵箱 $mail->FromName = "淘寶推薦---TaoBao"; // 發(fā)件人 ,比如 中國(guó)資金管理網(wǎng) $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; // 郵件內(nèi)容 可以直接發(fā)送html文件 $mail->Body = $body; $mail->AltBody ="text/html"; if($mail->Send()) { info_write(ROOT_PATH.'/log/'.$batch_no."ok.txt","$user_name 發(fā)送成功"); } else { info_write(ROOT_PATH.'/log/'.$batch_no."falied.txt","$user_name 失敗,發(fā)送賬號(hào)".$sender_info['Username'].",錯(cuò)誤信息$mail->ErrorInfo"); if($senderListConf[$sender+1]) { $sender = smtp_mail ( $sendto_email, $subject, $body, $extra_hdrs, $user_name,$senderListConf,($sender+1)); } } return $sender; }
發(fā)送郵件列表示例 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實(shí)現(xiàn)郵件群發(fā)的源碼
- thinkphp實(shí)現(xiàn)163、QQ郵箱收發(fā)郵件的方法
- PHP實(shí)現(xiàn)發(fā)送郵件的方法(基于簡(jiǎn)單郵件發(fā)送類)
- php利用smtp類實(shí)現(xiàn)電子郵件發(fā)送
- php郵件發(fā)送的兩種方式
- php的mail函數(shù)發(fā)送UTF-8編碼中文郵件時(shí)標(biāo)題亂碼的解決辦法
- php可擴(kuò)展的驗(yàn)證類實(shí)例(可對(duì)郵件、手機(jī)號(hào)、URL等驗(yàn)證)
- PHP配置把錯(cuò)誤日志以郵件方式發(fā)送方法(Windows系統(tǒng))
- PHP的郵件群發(fā)系統(tǒng)phplist配置方法詳細(xì)總結(jié)
相關(guān)文章
PHP獲取數(shù)組表示的路徑方法分析【數(shù)組轉(zhuǎn)字符串】
這篇文章主要介紹了PHP獲取數(shù)組表示的路徑,結(jié)合實(shí)例形式對(duì)比分析了數(shù)組轉(zhuǎn)字符串的實(shí)現(xiàn)技巧,需要的朋友可以參考下2017-09-09PHP mysql事務(wù)問(wèn)題實(shí)例分析
這篇文章主要介紹了PHP mysql事務(wù)問(wèn)題,結(jié)合實(shí)例形式分析了PHP操作MySQL的myisam數(shù)據(jù)庫(kù)實(shí)現(xiàn)控制事務(wù)的相關(guān)技巧,需要的朋友可以參考下2016-01-01詳談php中 strtr 和 str_replace 的效率問(wèn)題
下面小編就為大家?guī)?lái)一篇詳談php中 strtr 和 str_replace 的效率問(wèn)題。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-05-05PHP手機(jī)號(hào)碼及郵箱正則表達(dá)式實(shí)例解析
這篇文章主要介紹了PHP手機(jī)號(hào)碼及郵箱正則表達(dá)式實(shí)例解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-07-07