Skip to content
Advertisement

clear last exception error from PHPMailer for next loop

lets say i have this:

JavaScript

so the exception in next loop is remembered and displayed, the output above is:

JavaScript

so my question is, how do i clear the error after i process it so i can start fresh?

Advertisement

Answer

Because of the exception at the second address, the line with $mail->clearAddresses() is never reached.

So your third mail wil be sent to both some2@email and some3@email.com, throwing the exception again.

JavaScript

You can call $mail->clearAddresses() outside of the try, catch statement.

JavaScript

You can also call $mail->clearAddresses() before you call $mail->addAddress($email). That way you will always be sure the addresses are cleared before you add one.

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement