clearAttachments(); // ... send email ?>
addAttachment('path/to/image1.jpg'); $mail->addAttachment('path/to/image2.jpg'); // ... set up email settings and send email if ($someCondition) { $mail->clearAttachments(); } else { $mail->addAttachment('path/to/image3.jpg'); } $mail->send(); ?>In this example, we create a new PHPMailer object, add two attachments and set up the email settings. We then check some condition and either remove all attachments using clearAttachments() or add a new attachment using addAttachment(). Finally, we send the email message. Package Library: The clearAttachments() method is a part of the PHPMailer library that is available on GitHub at https://github.com/PHPMailer/PHPMailer.