PHPMailer 在循环中发送重复项 [英] PHPMailer sends duplicates in a loop

查看:66
本文介绍了PHPMailer 在循环中发送重复项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have this problem like some people with PHPMailer, and I cannot find any solutions on the internet. The problem is that PHPMailer sends duplicates (sometimes more than two) if I set it in a loop (while, foreach). I've checked the loop is just fine, but it keeps sending duplicates.

这是我简化后的代码.

<?
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 封邮件.

I think I need to reset mail->addaddress inside the loop, but mail->clearaddresses doesn't help. And all 3 emails always receives the same emails. So all receives 2 or 3 mails.

有人能帮我吗??谢谢.哎哟

Could anyone help me out here?? Thanks. ayok

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

The problem get even wierder... I've tried to change the code to just a simple mail(), and it keep sending duplicates. What could be the cause? Is it a server configuration problem??

我在 mysite.com 的子域中执行此操作,例如 sub.mysite.com.Mysite.com 和 sub.mysite.com 在不同的服务器上.会不会是原因?

I did this in the subdomain of mysite.com, say sub.mysite.com. Mysite.com and sub.mysite.com are in different servers. Could it be the cause?

谢谢,哎哟

推荐答案

我已经处理了您发布的代码.我认为代码没有问题.

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

我认为每当您刷新页面时,邮件就会被触发.

所以请保持邮件代码的状态,然后检查您收到了多少邮件.希望这个回答能帮到你.

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

这篇关于PHPMailer 在循环中发送重复项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆