I have been writing a trigger that mails an email using PHP mailer. The problem with the code is that it is sending multiple mails to a single recipient. I even tried using the
AddAddress()
simply adds a new address to the end of an array of addresses. If you want to send individual emails, per-address, you'll have to clear that list on each iteration, e.g.
for(...) {
$mail->AddAddress(...);
$mail->send();
$mail->ClearAddresses(); // <---you need this line.
}
If a single user is receiving multiple emails, then you'd need some code to detect when you've already sent one, e.g.:
$sent = array();
for(...) {
if (isset($sent[$email[$i]])) {
continue; // check if sent already, skip if so
}
...
if ($mail->send()) {
$sent[$email[$i]] = true; // flag address as already sent
}
}