$mail = new PHPMailer(); // Set up email message... $mail->addAddress('john@example.com'); $mail->addCC('jane@example.com'); // Reset recipients and add new ones... $mail->clearAllRecipients(); $mail->addAddress('bill@example.com'); $mail->addCC('susan@example.com');
$mail = new PHPMailer(); // Set up email message... $mail->addAddress('john@example.com'); $mail->addCC('jane@example.com'); // Remove all recipients... $mail->clearAllRecipients();In this example, we first add two recipients to the email message. Then, we remove all recipients using clearAllRecipients. Package library: PHPMailer As mentioned earlier, clearAllRecipients is a method of PHPMailer library. It is used to reset or remove all recipients from an email message. This method can help you avoid errors where you accidentally send an email to the wrong recipient or add duplicate recipients. It is also useful if you need to change the recipients dynamically based on some conditions.