点击(此处)折叠或打开

  1. <?php
  2.     require_once ('class.phpmailer.php');
  3.     //发送Email函数
  4.     function smtp_mail($sendto_email, $subject, $body,$extra_hdrs, $user_name){
  5.         $mail = new PHPMailer();
  6.         $mail->IsSMTP();
  7.         $mail->Host="smtp.163.com";
  8.         $mail->SMTPAuth = true;
  9.         $mail->Username = "name" //SMTP username,普通邮件认证部需要加@域名
  10.         $mail->Password = "123456";
  11.         $mail->From = "name@163.com"
  12.         $mail->FromName="XX网站";
  13.         $mail->CharSet="GB2312";
  14.         $mail->Encoding = "base64";
  15.         $mail->AddAddress($sendto_email,$user_name); //$user_name可省略
  16.         $mail->AddReplyTo("name@qq.com","XX科技公司"); //回复给name@qq.com邮箱

  17.         $mail->wordwrap = 50;
  18.         $mail->AddAttachment("/var/tmp/file.tgz"); //附件1
  19.         $mail->AddAttachment("/tmp/image.jpg","new.jpt"); //附件2

  20.         $mail->IsHTML(true);
  21.         $mail->Subject = $subject;
  22.         $mail->Body = <<<EOT
  23.         <html>
  24.         <head>
  25.         <meta http-equiv="Content-Language" c>
  26.         <meta http-equiv="Content-Type" c>
  27.         </head>
  28.         <body>
  29.             {$user_name}您好,欢迎你注册本站用户!
  30.         </body>
  31.         </html>
  32.         EOT;

  33.         $mail->AltBody="text/html";
  34.         if($mail-Send()){    
  35.             info_write("ok.txt","$user_name发送成功");
  36.         }else{
  37.             info_write("falied.txt","$user_name发送失败,错误信息$mail->ErrorInfo");
  38.         }

  39.     }

  40.     function info_write($filename,$info_log){
  41.         $info.= $info_log;
  42.         $info.="\r\n";
  43.         $fp = fopen($filename,a);
  44.         fwrite($fp,$info);
  45.         fclose($fp);
  46.     }
  47. //定时跳转到页面函数,1000是1秒,可自定义
  48.     function redirect($url){
  49.         echo "<script>
  50.         functon redirect(){
  51.             window.location.replace('$url');
  52.         }
  53.             window.setTimeout('redirect();',15000);

  54.         </sctipt>";
  55.     }

  56. //读取文本邮件地址,也可以读数据库
  57.     $filename = "email.txt";
  58.     $fp = fopen($filename,"r");
  59.     $contents = fread($fp,filesize($filename));
  60.     $num_email=explode("\r\n",$contents);
  61.     $len = count($num_email);
  62.     fclose($fp);
  63. //参数说明(发送到,邮件主题,内容,附件,用户名)
  64.     $i = $_GET['action'];
  65.     $i++;
  66.     if($i<$len){
  67.         $rs=explode("@",$num_email[$i]);
  68.         $user_name = $rs['0'];
  69.         echo "正在发送第{$i}封({$num_email[$i]})邮件。。。";
  70.         smtp_mail($num_email[$i],'XX周刊第十期',
  71.             $body,'http://jc258.com',$user_name);
  72.         redirect("?action=$i");
  73.     }else{
  74.         echo "邮件全部发送完毕";
  75.         exit;
  76.     }

  77. ?>