What is the recommended approach for sending mass emails using PHPMailer, especially when dealing with multiple recipients and the use of BCC?

When sending mass emails using PHPMailer, it is recommended to loop through your list of recipients and send individual emails to each recipient to avoid exposing recipients' email addresses. When using BCC (Blind Carbon Copy) to hide recipients' email addresses, you can add multiple recipients to the BCC field without revealing their email addresses to each other.

// Include PHPMailer autoload file
require 'vendor/autoload.php';

// Create a new PHPMailer instance
$mail = new PHPMailer();

// Loop through your list of recipients
$recipients = ['recipient1@example.com', 'recipient2@example.com', 'recipient3@example.com'];
foreach ($recipients as $recipient) {
    // Set the recipient's email address
    $mail->addAddress($recipient);

    // Add multiple recipients to BCC field
    $mail->addBCC('bcc1@example.com');
    $mail->addBCC('bcc2@example.com');

    // Set email subject and body
    $mail->Subject = 'Your email subject';
    $mail->Body = 'Your email body content';

    // Send the email
    if (!$mail->send()) {
        echo 'Message could not be sent.';
        echo 'Mailer Error: ' . $mail->ErrorInfo;
    } else {
        echo 'Message has been sent';
    }

    // Clear all addresses and attachments for the next iteration
    $mail->clearAddresses();
    $mail->clearBCCs();
}