Fix Multiple Recipients in PHPMailer

0
98

If you’re looping through sending an email to multiple recipients and you’re using PHPMailer then you may see that the TO: line get’s longer and longer. PHPMailer doesn’t seem to reset the variable for recipients like you think it would. Fortunately, this is an easy to fix bug. Simply add this line to your loop:

$this->phpmailer->ClearAddresses();

And, for good measure, I also add the following:

$this->phpmailer->ClearAllRecipients();

And then it’s problem solved!