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 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)