doutao4938 2012-02-13 17:06
浏览 60
已采纳

添加多个接收器时,PHPMailer 5.1会发送重复的电子邮件

I'm using PHPMailer for a while now and never really had any problems, but last week I installed one of my CMS on a website and the client insisted on having 2 e-mails receiving the contents of the contact form of his website.

Ok, no problem I thought, just adding an e-mail address using the $phpmailer->AddAddress() function. However, adding a second receiver is causing PHPMailer to send the mail twice to both receivers. I tried adding a third receiver to see if I got it three times, but this didn't change anything. So adding 2+ receivers is causing PHPMailer to send the message twice to all receivers.

There's nothing strange in my code. It's a basic PHPMailer example:

$mail             = new PHPMailer();
$mail->AddReplyTo("name@yourdomain.com","First Last");
$mail->SetFrom('name@yourdomain.com', 'First Last');

$mail->AddAddress("info@address.com");
$mail->AddAddress("info@address.nl");
$mail->Subject    = "PHPMailer Test Subject via mail(), basic"; 

$mail->Send();

I've ran out of options. I have absolutely no clue where it's going wrong.

Thanks in advance

--

Just some random thought: I noticed the mailer is defaulted by iso-8859-1 and my site is running utf8. Can there be a "silent" redirect by the server itself?

//EDIT, that ^^ solved my problem

//EDIT2:

Ok, it did not.. today the script worked fine (just 1 mail with 2 receivers) but a moment ago the strange behavior started again. Any tips?

// Solution:

ok, I feel quiet stupid! The answer Zulkhaery Basrul came closest to the actual problem! This is what happened: I was sending an e-mail to multiple addresses in the "to" field. For example:

To: A, B, C

Both A/B are my own adresses. In outlook I had some message rules to put e-mails with certain addressees inside a specific folder. Both A and B had this rule.

When I recieved my e-mail, both mails contained both mailaddresses in the to-field. Causing both of the mails to meet the rule requirements for both rules. Thus keeping the original in one folder and creating a copy in the other (twice).

Thanks for thinking tho :)

  • 写回答

7条回答 默认 最新

  • doujiang5211 2012-02-18 15:29
    关注

    You can use $SingleTo property.

    From PHPMailer docs:

    $SingleTo

    Provides the ability to have the TO field process individual emails, instead of sending to entire 'TO addresses'

    $mail = new PHPMailer();
    
    $mail->SingleTo = true; //will send mail to each email address individually
    
    
    $mail->AddReplyTo("name@yourdomain.com","First Last");
    $mail->SetFrom('name@yourdomain.com', 'First Last');
    
    $mail->AddAddress("info@address.com");
    $mail->AddAddress("info@address.nl");
    $mail->Subject    = "PHPMailer Test Subject via mail(), basic"; 
    
    $mail->Send();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(6条)

报告相同问题?

悬赏问题

  • ¥15 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了