phpmailer批量发送邮件的问题

今天用phpmymailer发送邮件碰到一个问题?本来这样想发是用 循环给每个用户发送邮件

 1  for ( $i = 1 ; $i < count ( $rms ); $i ++ ){
 2   
 3       if (send_mail( $to ,   $subject ,   $message )){
 4                   $ma .= "  -  " . $rmail [username];
 5                   sleep ( 1 );
 6              } else {
 7               $ms .= "  -  " . $rmail [username];
 8              }    
 9   
10      }

 

现实总是比较曲折,每次都发送一份邮件之后 它就罢工了。

为什么呢?用zend debug调试发现循环到第一次就不循环了。

追踪send_mail函数

 

 1  require ( & quot; class . phpmailer . php & quot;);
 2   
 3  function  send_mail( $F_mail , $F_sunject , $F_html , $F_text =& quot; 2 & quot; , $F_name =& quot;test & quot;){
 4   
 5       $mail   =   new  PHPMailer();
 6       $mail -> IsSMTP();         //  set mailer to use SMTP
 7       $mail -> Host  =   & quot;smtp . 163 . com & quot;;   //  邮件供应商的服务器地址   specify main and backup server
 8       $mail -> SMTPAuth  =   true ;      //  验证开启  turn on SMTP authentication
 9       $mail -> Username  =   & quot;nameliang010 & quot;;   //  你的邮箱用户名    SMTP username
10       $mail -> Password  =   & quot;email = ytmf + ypmb & quot;;  //  你的邮箱密码    SMTP password
11   
12       $mail -> From  =   & quot;nameliang010@ 163 . com & quot;;    // 发件箱地址
13       $mail -> FromName  =   & quot; & quot;;                 // 发送者姓名
14       $mail -> AddAddress( $F_mail );    // 收件箱地址
15   
16   
17       if ( ! $mail -& gt;Send())
18      {
19           return   false ;
20      }
21       return   true ;
22  }

 

无果,后来不小心把require改为require_once就可以了 为什么呢?

我它们的区别是require_once是载入一次,下次载入就判断是否载入过,如果载入过就不在载入。

为什么呢?查手册原来还有一点。应该用于在脚本执行期间同一个文件有可能被包含超过一次的情况下,

想确保它只被包含一次以避免函数重定义,变量重新赋值等问题


$mail对象被构造了两次,而phpmailer的对象不可以同时链接。所以失败。


 

你可能感兴趣的:(phpmailer)