PHP郵件群發(fā)機實現(xiàn)代碼
原理:
第一:申請大量的郵箱帳號 騰訊的 126的 163的 新浪的 雅虎的 谷歌的 等等提供smtp服務(wù)的
第二:收集你要發(fā)送郵件的郵件列表
第三:遍歷郵件列表,每一個郵件發(fā)送郵件
第四:用linux下定時腳本后臺運行 我跑了兩天 哈哈 ,因為為了盡可能的保證每一個都發(fā)送成功
原理是很簡單,但是其中還是遇到很多的問題。
第一:郵件失敗的問題,我這里采用兩個方式解決,第一把大量的那些郵箱帳號依次去發(fā)送,直到成功。然后每次發(fā)送500封郵件 后把發(fā)送郵箱列表隨機打散(避免一個持續(xù)失?。?。
我用的是phpmailer
多的不多說了上代碼了。phpmailer 大家自己搜索下載吧
入口腳本:就是linux 執(zhí)行的 mail_001.php
<?php
define('ROOT_PATH',dirname(__FILE__));
require_once 'library/senderApi.php'; //發(fā)送郵件接口
require_once 'config/senderListConf.php'; //發(fā)送郵件帳號列表
//讀取文本 郵件地址
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)頁上的內(nèi)容
$htmlContent = file_get_contents('http://taobao.1080www.com');
// 參數(shù)說明(發(fā)送到, 郵件主題, 郵件內(nèi)容, 附加信息, 用戶名)
foreach($list_email as $key=>$value)
{
$value = trim($value);
$rs=explode("@",$value);
$user_name = $rs['0'];
smtp_mail($value, '秋季補水化妝品_秋季護膚皮膚保養(yǎng)_秋天皮膚干燥怎么辦-小常識',$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
// 請求 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ā)送帳號出錯了..............'; // 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ā)件人 ,比如 中國資金管理網(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ā)送賬號".$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;
}
發(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'),
);
相關(guān)文章
PHP中simplexml_load_string函數(shù)使用說明
這個問題遇到好幾次了,今天翻看以前代碼的時候看到,便記下來,需要的朋友可以參考下。2011-01-01
php+resumablejs實現(xiàn)的分塊上傳 斷點續(xù)傳功能示例
這篇文章主要介紹了php+resumablejs實現(xiàn)的分塊上傳 斷點續(xù)傳功能,結(jié)合實例形式分析了php+resumablejs文件傳輸?shù)木唧w實現(xiàn)步驟與相關(guān)操作技巧,需要的朋友可以參考下2017-04-04
PHP實現(xiàn)補齊關(guān)閉的HTML標(biāo)簽
這篇文章主要介紹了PHP實現(xiàn)補齊關(guān)閉的HTML標(biāo)簽的方法,通過自定義函數(shù)實現(xiàn)針對HTML標(biāo)簽的閉合補全功能,涉及PHP字符串及正則匹配相關(guān)操作技巧,需要的朋友可以參考下2016-03-03
echo(),print(),print_r()之間的區(qū)別?
echo(),print(),print_r()之間的區(qū)別?...2006-11-11

