欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PHP郵件群發(fā)機(jī)實(shí)現(xiàn)代碼

 更新時(shí)間:2016年02月16日 22:36:18   投稿:mdxy-dxy  
這篇文章主要介紹了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'), 
);

相關(guān)文章

最新評(píng)論