php邮件发送yuanchengxu,邮件群发代码_php smtp邮件群发程序源代码
摘要 騰興網(wǎng)為您分享:php smtp郵件群發(fā)程序源代碼,篆刻字典,易通行,學(xué)習(xí)計時,小米社區(qū)等軟件知識,以及鴻業(yè)暖通8.0,故事口袋聽聽,證件照,幫我關(guān)下燈,手淘鏈接轉(zhuǎn)換,魅族,紅包軟件,gif修改軟件,青海建筑職業(yè)技術(shù)學(xué)院,九天劍神,死亡空間2武器,音頻剪輯軟件,藍(lán)手指論壇,博秀,湖北客運集團(tuán)等軟件it資訊,歡迎關(guān)注騰興網(wǎng)。?*@author ray *@since 2009-08-07 */ define('__DEBUG__', false); define('__PSW_FILE__', dirname(__FILE__) . '/smtp.dat'); define('SLEEPING_EMAIL', dirname(__FILE__) . /sleepMail.dat);//休眠的email define('SLEEPING_TIME', 1800);//休眠多長...
*@author ray
*@since 2009-08-07
*/
define('__DEBUG__', false);
define('__PSW_FILE__', dirname(__FILE__) . '/smtp.dat');
define('SLEEPING_EMAIL', dirname(__FILE__) . "/sleepMail.dat");//休眠的email
define('SLEEPING_TIME', 1800);//休眠多長時間,以秒為單位
define('FILE_APPEND', 1);
if (!function_exists('file_put_contents')) {
function file_put_contents($n, $d, $flag = false) {
$mode = ($flag == FILE_APPEND || strtoupper($flag) == 'FILE_APPEND') ? 'a' : 'w';
$f = @fopen($n, $mode);
if ($f === false) {
return 0;
} else {
if (is_array($d)) $d = implode($d);
$bytesWritten = fwrite($f, $d);
fclose($f);
return $bytesWritten;
}
}
}
$errorNo = 0;
$errorMsg = '';
$currTime = time();
$unuseMails = array();
//收件人和郵件標(biāo)題和郵件內(nèi)容
$to = isset($argv[1]) ? $argv[1] : "" ;
$subject = isset($argv[2]) ? $argv[2] : "";
$mailFile = isset($argv[3]) ? $argv[3] : "" ;
if (__DEBUG__) {
echo "
file:$mailFile to:$to subject:$subjectrn";
}
if (empty($mailFile) || empty($to) || empty($subject)) {
$errorNo = 1;
$errorMsg = "參數(shù)不全";
}
//加載不可用的email列表
if (!$errorNo) {
if (file_exists(SLEEPING_EMAIL)) {
$sleepMails = file(SLEEPING_EMAIL);
if (!empty($sleepMails)) {
foreach($sleepMails as $sleepMail) {
//解析
if (false !== strpos($sleepMail, '|')) {
$tmp = explode('|', $sleepMail);
if (isset($tmp[0]) && isset($tmp[1])) {
$mail = trim($tmp[0]);
$time = trim($tmp[1]);
//是否可用
if ( ($currTime - $time )< SLEEPING_TIME) {
$unuseMails[] = $mail;
}
}
}
}
}
}
}
if (!$errorNo) {
//隨機(jī)加載smtp服務(wù)器和smtp用戶名和密碼
$info = file(__PSW_FILE__);
$len = count($info);
do {
$rnd = mt_rand(0, $len - 1);
$line = isset($info[$rnd]) ? $info[$rnd] : "";
if (false !== strpos($line, '|')) {
$tmp = explode('|', $line);
if (isset($tmp[0]) && isset($tmp[1]) && isset($tmp[2])) {
$smtpServer = trim($tmp[0]);
$fromMail = trim($tmp[1]);
$'@'));
}
}
}while (in_array($fromMail, $unuseMails));//如果在不可用的列表中,在次加載
if (!isset($smtpServer) || !isset($fromMail) || !isset($psw)) {
$errorNo = 2;
$errorMsg = "沒找到發(fā)件人QQ信箱和密碼";
}
}
if (!$errorNo && __DEBUG__) {
echo "smtp:$smtpServer from:$fromMail psw:$psw user:$smtpUserNamern";
}
if (!$errorNo) {
//通過phpmailer連接smtp服務(wù)器發(fā)信
require(dirname(__FILE__) . "/phpmailer/class.phpmailer.php");
require(dirname(__FILE__) . "/phpmailer/class.smtp.php");
$mail = new PHPMailer();
$body = $mail->getFile($mailFile);
$body = eregi_replace("[]",'',$body);
//charset
$mail->CharSet = "GB2312";
//$mail->SMTPDebug = 2;//用于顯示具體的smtp錯誤
$mail->IsSMTP();
$mail->SMTPAuth = true;
if ("smtp.qq.com" == trim($smtpServer)) {
$mail->Username = $fromMail;
} else {
$mail->Username = $smtpUserName;
}
$mail->Password = $psw;
$mail->Host = $smtpServer;
$mail->From = $fromMail;
$mail->FromName = "晴天網(wǎng)絡(luò)";
$mail->IsHTML(true);
$mail->AddAddress($to);
$mail->Subject = $subject;
$mail->Body = $body;
if (!$mail->Send()) {
// echo "Message could not be sent. ";
$errorNo = 3;
$errorMsg = $mail->ErrorInfo;
} else {
echo "
Send to $to success use $fromMailrn";
exit;
}
}
if (3 == $errorNo) {
//記錄信息,該信息地址休眠N分鐘
$content = "$fromMail|" . time() . "rn";//email|當(dāng)前時間戳
file_put_contents(SLEEPING_EMAIL, $content, FILE_APPEND);
}
echo "
Error No($errorNo) " . $errorMsg . "rn";
exit;
?>
相關(guān)推薦
總結(jié)
以上是生活随笔為你收集整理的php邮件发送yuanchengxu,邮件群发代码_php smtp邮件群发程序源代码的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 2023大连理工大学考研分析
- 下一篇: 记录钱德拉望远镜天文软件ciao的一些简