php phpMailer - 你如何删除收件人
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10952441/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
phpMailer - How do you Remove Recipients
提问by Joe Majewski
There are a lot of StackOverflow questions on this topic, but I couldn't find one that was able to help with the issue I'm having. The script that I'm writing sends out multiple emails to various recipients with different message contents.
关于这个主题有很多 StackOverflow 问题,但我找不到一个能够帮助解决我遇到的问题的问题。我正在编写的脚本向具有不同消息内容的不同收件人发送多封电子邮件。
I can get this working by re-initializing the phpMailerobject multiple times, but what I'd like to be able to do is create the object a single time, and then re-assign the following fields:
我可以通过phpMailer多次重新初始化对象来使其工作,但我希望能够做的是一次创建对象,然后重新分配以下字段:
$mail->AddAddress($email);
$mail->Subject = $subject;
$mail->IsHTML(false);
$mail->Body = $message;
That way I can just run those four lines of code and then send the mail out, again and again, as many times as necessary. The Subject, IsHTML, and Bodyfields are easily changed, so the problem I'm having is in the AddAddressfunction.
这样我就可以运行这四行代码,然后根据需要一次又一次地发送邮件。的Subject,IsHTML和Body字段被轻易改变,所以我遇到的问题是在AddAddress函数。
As you can probably guess, after I send out the first email, changing recipients for future emails will result in those stacking onto the current list of recipients.
正如您可能猜到的那样,在我发送第一封电子邮件后,更改未来电子邮件的收件人将导致这些收件人堆叠到当前收件人列表中。
To put it simply, how can I remove the email addresses associated with my $mailobject so that I can assign them each time while removing the old addresses?
简而言之,如何删除与我的$mail对象关联的电子邮件地址,以便在删除旧地址时每次都可以分配它们?
Is there another function besides AddAddressthat I can use that will just assign the addresses?
除了AddAddress我可以使用的仅分配地址的功能之外,还有其他功能吗?
回答by GDP
You can use ClearAllRecipients( )
您可以使用ClearAllRecipients()
$mailer->ClearAllRecipients( ); // clear all
$mailer->ClearAllRecipients( ); // clear all
回答by Joe Majewski
im using this always before sending email to recipients:
我总是在向收件人发送电子邮件之前使用它:
// clear addresses of all types
$mail->ClearAddresses(); // each AddAddress add to list
$mail->ClearCCs();
$mail->ClearBCCs();
then im doing just this: (not using CC or BCC, $toaddressis just an array of recipients)
然后我就这样做了:(不使用抄送或密件抄送,$toaddress只是一组收件人)
foreach($toaddress as $key=>$val) { $mail->AddAddress( $val ); }
im using PHPMailer 5.2
我正在使用 PHPMailer 5.2

