Are there any security considerations when sending emails to multiple recipients using PHP?

When sending emails to multiple recipients using PHP, it is important to be mindful of potential security vulnerabilities such as exposing email addresses of all recipients in the "To" field. To address this issue, it is recommended to use the BCC (Blind Carbon Copy) field to send emails to multiple recipients without revealing their email addresses to each other.

$to = "recipient1@example.com";
$subject = "Subject";
$message = "Message";

$recipients = array("recipient2@example.com", "recipient3@example.com");

$headers = "From: sender@example.com\r\n";
foreach ($recipients as $recipient) {
    $headers .= "Bcc: $recipient\r\n";
}

mail($to, $subject, $message, $headers);