dporu02280
2016-09-16 15:51
浏览 224
已采纳

PHPMailer在发送电子邮件时显示列表中的所有收件人?

I'm using PHPMailer to send emails. I've use it inside a foreach loop in order to send an email to a list of recipients.

It is working, because the email is being sent, but each recipient receives the whole list of recipients!

foreach ($id as $item) {
        $mail->addAddress($item);
        $mail->Subject = $correo['mailAsunto'];
        $mail->Body    = $correo['mailMensaje'];
        if(!$mail->send()) {
            echo 'Error: ' . $mail->ErrorInfo;
        } else { 
          echo 'Mail sent to '.$item.'<br>';
        }
}

I've tried: $mail->AddBCC($item); instead of addAddress but the email can still be seen in the "TO" header.

What may I do? This can have serious privacy implications.

UPDATE

Just in case anyone has a similar issue, after the responses received, here's how the code is now:

foreach ($id as $item) {
        $mail->addAddress($item);
        $mail->Subject = $correo['mailAsunto'];
        $mail->Body    = $correo['mailMensaje'];
        if(!$mail->send()) {
            echo 'Error: ' . $mail->ErrorInfo;
        } else { 
          echo 'Mail sent to '.$item.'<br>';
                    $mail->ClearAddresses(); 
                    $mail->ClearAllRecipients();
        }
}

图片转代码服务由CSDN问答提供 功能建议

我正在使用PHPMailer发送电子邮件。 我在foreach循环中使用它以便向收件人列表发送电子邮件。

它正在工作,因为正在发送电子邮件,但每个收件人都收到整个列表 收件人!

  foreach($ id as $ item){
 $ mail-&gt; addAddress($ item); 
 $ mail-&gt; Subject = $ correo  ['mailAsunto']; 
 $ mail-&gt; Body = $ correo ['mailMensaje']; 
 if(!$ mail-&gt; send()){
 echo'Error:'。  $ mail-&gt; ErrorInfo; 
} else {
 echo'mail'发送到'。$ item。'&lt; br&gt;'; 
} 
} 
   
 \  n 

我试过: $ mail-&gt; AddBCC($ item); 而不是 addAddress 但电子邮件仍然可以在“TO”标题中看到 。

我该怎么办? 这可能会产生严重的隐私隐患。

更新

万一有人遇到类似问题,收到回复后,以下是代码的现状 :

  foreach($ id as $ item){
 $ mail-&gt; addAddress($ item); 
 $ mail-&gt; Subject = $ correo ['  mailAsunto']; 
 $ mail-&gt; Body = $ correo ['mailMensaje']; 
 if(!$ mail-&gt; send()){
 echo'Error:'。  $ mail-&gt; ErrorInfo; 
} else {
 echo'mail'发送到'。$ item。'&lt; br&gt;'; 
 $ mail-&gt; ClearAddresses();  
 $ mail-&gt; ClearAllRecipients(); 
} 
} 
   
 

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • du7999 2016-09-16 15:58
    已采纳

    You are adding the addresses to the same object, so they are being accumulated. Try deleting each address after sending the message to it:

    foreach ($id as $item) {
            $mail->addAddress($item);
            $mail->Subject = $correo['mailAsunto'];
            $mail->Body    = $correo['mailMensaje'];
            if(!$mail->send()) {
                echo 'Error: ' . $mail->ErrorInfo;
            } else { 
              echo 'Mail sent to '.$item.'<br>';
            }
            $mail->ClearAllRecipients();    ◄■■■■■■■■■■■■■■■■■■■■■■■■■
    }
    
    点赞 评论
  • dreinuqm992401 2016-09-16 15:57

    Assuming this the right PHPMailer github repo, look at https://github.com/PHPMailer/PHPMailer/blob/master/class.phpmailer.php#L358. You will want to set that flag to true. Then, wait until after your loop to execute the send function.

    点赞 评论

相关推荐 更多相似问题