Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
444 views
in Technique[技术] by (71.8m points)

php - phpMailer - How do you Remove Recipients

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can use clearAllRecipients( )

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...