Skip to content
PHP Logo

What are common issues with sending emails in PHP, specifically with the Cc and Bcc fields?

Common issues with sending emails in PHP, specifically with the Cc and Bcc fields, include not properly formatting the email addresses or accidentally exposing the email addresses to recipients. To solve this, make sure to separate multiple email addresses with commas and use the appropriate headers to set the Cc and Bcc fields.

php
$to = "recipient@example.com";
$subject = "Testing Cc and Bcc fields";
$message = "This is a test email.";

$cc = "cc1@example.com, cc2@example.com";
$bcc = "bcc1@example.com, bcc2@example.com";

$headers = "From: sender@example.com\r\n";
$headers .= "Cc: $cc\r\n";
$headers .= "Bcc: $bcc\r\n";

// Send email
mail($to, $subject, $message, $headers);