0

我和一些使用 PHPMailer 的人一样有这个问题,我在互联网上找不到任何解决方案。问题是如果我将它设置在一个循环中(while,foreach),PHPMailer 会发送重复项(有时超过两个)。我检查了循环很好,但它不断发送重复。

这是我使它看起来更简单之后的代码。

<?
require("PHPMailer/class.phpmailer.php");
$select = mysql_query("SELECT * FROM `pm_mailmembers` WHERE `mm_interval`='2' AND   mm_blocked = 0") or die(mysql_error());
$mail = new PHPMailer();
$mail->SingleTo = true;
$mail->CharSet = "UTF-8";
$mail->Subject = "Fiscanet Nieuws";
$sendContent = "<p>This is test mail</p>";
$r_receivers = array("John"=>"john@mail.com","Mary"=>"mary@mail.com","Rob"=>"rob@mail.com");
foreach($r_receivers as $name=>$email){
    $mail->SetFrom('no-reply@yoursite.com', "Yoursite");
    $mail->MsgHTML($sendContent);
    $mail->AddAddress($email, $name);
    if($mail->Send())
        echo "Sent to: ".$email."<br/>";
    else
        echo "Not sent to: ".$email.", reason: ".$mail->ErrorInfo."<br/>";
    $mail->ClearAddresses();
}
?>

我想我需要在循环内重置 mail->addaddress,但 mail->clearaddresses 没有帮助。并且所有 3 封电子邮件总是收到相同的电子邮件。所以所有人都会收到 2 或 3 封邮件。

有人可以帮我吗?谢谢。哎哟


问题变得更加奇怪......我试图将代码更改为只是一个简单的mail(),并且它不断发送重复。可能是什么原因?是服务器配置问题吗??

我在 mysite.com 的子域中执行此操作,例如 sub.mysite.com。Mysite.com 和 sub.mysite.com 位于不同的服务器中。这可能是原因吗?

谢谢,好的

4

3 回答 3

1

I have worked on the code you posted. I think there is no problem with the code.

I think when ever you refresh your page the mail is fired.

So Please keep the mail code in condition and then check how many mails you get. I hope this answer might help you.

于 2012-06-18T13:30:26.940 回答
0

顺便说一句,我已经为内容设定了时间。副本在第一个后 6 分钟发送。我还设置了一个订单号,所有重复的订单号都相同。

<?php
require("PHPMailer/class.phpmailer.php");
$mail = new PHPMailer();
$mail->SingleTo = true;
$mail->CharSet = "UTF-8";
$mail->Subject = "Fiscanet Nieuws";
$r_receivers = array("John"=>"john@mail.com","Mary"=>"mary@mail.com","Rob"=>"rob@mail.com");
    $i = 1;
foreach($r_receivers as $name=>$email){
    $mail->SetFrom('no-reply@yoursite.com', "Yoursite");
    $mail->MsgHTML($sendContent);
    $mail->AddAddress($email, $name);
        $sendContent = "<p>This is test mail number ".$i." sent at ".date('H:i:s')."</p>";
    if($mail->Send())
        echo "Sent to: ".$email."<br/>";
    else
        echo "Not sent to: ".$email.", reason: ".$mail->ErrorInfo."<br/>";
    $mail->ClearAddresses();
            $i++;
}
?>
于 2012-06-19T14:07:48.910 回答
0

尝试

$mail->ClearAllRecipients();
于 2016-08-25T14:37:44.373 回答