phpMailer - How do you Remove Recipients

青春壹個敷衍的年華 提交于 2019-11-26 16:03:58

问题


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.

I can get this working by re-initializing the phpMailer object 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:

$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 Body fields are easily changed, so the problem I'm having is in the AddAddress function.

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 $mail object so that I can assign them each time while removing the old addresses?

Is there another function besides AddAddress that I can use that will just assign the addresses?


回答1:


You can use ClearAllRecipients( )

$mailer->ClearAllRecipients( ); // clear all




回答2:


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, $toaddress is just an array of recipients)

foreach($toaddress as $key=>$val) { $mail->AddAddress( $val ); }

im using PHPMailer 5.2



来源:https://stackoverflow.com/questions/10952441/phpmailer-how-do-you-remove-recipients

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!