Skip to content
PHP Logo

What are common pitfalls when sending emails to multiple recipients in PHP?

One common pitfall when sending emails to multiple recipients in PHP is not properly setting the headers for each recipient, which can result in recipients seeing each other's email addresses. To solve this issue, you should use the "Bcc" header to hide the email addresses of the other recipients.

php
$to = 'recipient1@example.com, recipient2@example.com';
$subject = 'Subject';
$message = 'Message';

$headers = 'From: sender@example.com' . "\r\n";
$headers .= 'Bcc: hiddenrecipient@example.com' . "\r\n";

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