点击(此处)折叠或打开
<?php
require_once ('class.phpmailer.php');
//发送Email函数
function smtp_mail($sendto_email, $subject, $body,$extra_hdrs, $user_name){
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host="smtp.163.com";
$mail->SMTPAuth = true;
$mail->Username = "name" //SMTP username,普通邮件认证部需要加@域名
$mail->Password = "123456";
$mail->From = "name@163.com"
$mail->FromName="XX网站";
$mail->CharSet="GB2312";
$mail->Encoding = "base64";
$mail->AddAddress($sendto_email,$user_name); //$user_name可省略
$mail->AddReplyTo("name@qq.com","XX科技公司"); //回复给name@qq.com邮箱
$mail->wordwrap = 50;
$mail->AddAttachment("/var/tmp/file.tgz"); //附件1
$mail->AddAttachment("/tmp/image.jpg","new.jpt"); //附件2
$mail->IsHTML(true);
$mail->Subject = $subject;
$mail->Body = <<<EOT
<html>
<head>
<meta http-equiv="Content-Language" c>
<meta http-equiv="Content-Type" c>
</head>
<body>
{$user_name}您好,欢迎你注册本站用户!
</body>
</html>
EOT;
$mail->AltBody="text/html";
if($mail-Send()){
info_write("ok.txt","$user_name发送成功");
}else{
info_write("falied.txt","$user_name发送失败,错误信息$mail->ErrorInfo");
}
}
function info_write($filename,$info_log){
$info.= $info_log;
$info.="\r\n";
$fp = fopen($filename,a);
fwrite($fp,$info);
fclose($fp);
}
//定时跳转到页面函数,1000是1秒,可自定义
function redirect($url){
echo "<script>
functon redirect(){
window.location.replace('$url');
}
window.setTimeout('redirect();',15000);
</sctipt>";
}
//读取文本邮件地址,也可以读数据库
$filename = "email.txt";
$fp = fopen($filename,"r");
$contents = fread($fp,filesize($filename));
$num_email=explode("\r\n",$contents);
$len = count($num_email);
fclose($fp);
//参数说明(发送到,邮件主题,内容,附件,用户名)
$i = $_GET['action'];
$i++;
if($i<$len){
$rs=explode("@",$num_email[$i]);
$user_name = $rs['0'];
echo "正在发送第{$i}封({$num_email[$i]})邮件。。。";
smtp_mail($num_email[$i],'XX周刊第十期',
$body,'http://jc258.com',$user_name);
redirect("?action=$i");
}else{
echo "邮件全部发送完毕";
exit;
}
?>