700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > php邮件发送yuanchengxu 邮件群发代码_php smtp邮件群发程序源代码

php邮件发送yuanchengxu 邮件群发代码_php smtp邮件群发程序源代码

时间:2024-02-01 08:38:46

相关推荐

php邮件发送yuanchengxu 邮件群发代码_php smtp邮件群发程序源代码

摘要 腾兴网为您分享:php smtp邮件群发程序源代码,篆刻字典,易通行,学习计时,小米社区等软件知识,以及鸿业暖通8.0,故事口袋听听,证件照,帮我关下灯,手淘链接转换,魅族,红包软件,gif修改软件,青海建筑职业技术学院,九天剑神,死亡空间2武器,音频剪辑软件,蓝手指论坛,博秀,湖北客运集团等软件it资讯,欢迎关注腾兴网。?*@author ray *@since -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 -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:$subjectrn";

}

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]);

$'@'));

}

}

}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:$smtpUserNamern";

}

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 ("" == 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 $fromMailrn";

exit;

}

}

if (3 == $errorNo) {

//记录信息,该信息地址休眠N分钟

$content = "$fromMail|" . time() . "rn";//email|当前时间戳

file_put_contents(SLEEPING_EMAIL, $content, FILE_APPEND);

}

echo "

Error No($errorNo) " . $errorMsg . "rn";

exit;

?>

相关推荐

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。