smtp邮件群发程序
时间:2009-08-09
来源:互联网
上程序[code]
<?php
/**
*通过phpmailer发送qq邮件
*@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();
//收件人和邮件标题和邮件内容
$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:$subject\r\n";
}
if (empty($mailFile) || empty($to) || empty($subject)) {
$errorNo = 1;
$errorMsg = "参数不全";
}
//加载不可用的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) {
//随机加载smtp服务器和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]);
$psw = trim($tmp[2]);
$smtpUserName = substr($fromMail, 0, strrpos($fromMail, '@'));
}
}
}while (in_array($fromMail, $unuseMails));//如果在不可用的列表中,在次加载
if (!isset($smtpServer) || !isset($fromMail) || !isset($psw)) {
$errorNo = 2;
$errorMsg = "没找到发件人QQ信箱和密码";
}
}
if (!$errorNo && __DEBUG__) {
echo "smtp:$smtpServer from:$fromMail psw:$psw user:$smtpUserName\r\n";
}
if (!$errorNo) {
//通过phpmailer连接smtp服务器发信
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 = "晴天网络";
$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 $fromMail\r\n";
exit;
}
}
if (3 == $errorNo) {
//记录信息,该信息地址休眠N分钟
$content = "$fromMail|" . time() . "\r\n";//email|当前时间戳
file_put_contents(SLEEPING_EMAIL, $content, FILE_APPEND);
}
echo "
Error No($errorNo) " . $errorMsg . "\r\n";
exit;
?>
[/code]今天试着用该程序给qq信箱发了700多个推广邮件,得出了以下几个结论:
1.smtp邮件帐号一定要多,不然会被qq服务器当作垃圾邮件。
2.得适当的休眠
smtp.dat文件格式为
smtp.163.com|[email protected]|密码
smtp.sina.com|[email protected]|密码
程序随机抽取一个连接,发送邮件,如果发送不成功,将该邮件地址存入sleepMail.dat休眠30分后在发送(这个是为了连接smtp服务器多次后发送不成功而做的修改)。
作者: appz 发布时间: 2009-08-09
作者: appz 发布时间: 2009-08-09
作者: 冯.于安 发布时间: 2009-08-09
作者: appz 发布时间: 2009-08-09
作者: zozo 发布时间: 2009-09-20
作者: kupe 发布时间: 2009-09-24
国内还是有点市场的..不过已经有了.
当然要写的话,还是用c吧..效率上差一个级别.群发都是万以上的
作者: 菜头 发布时间: 2009-10-03

作者: alei817927 发布时间: 2009-10-04
作者: mailangel123 发布时间: 2009-10-17
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28