Add cc in php mail
To add a CC (Carbon Copy) recipient to a PHP mail, you can use the cc
parameter when calling the mail()
function. Here's an example:
<?php
$to = '[email protected]';
$subject = 'Test email';
$message = 'This is a test email';
// Add CC recipient
$cc = '[email protected]';
// Set up the mail headers
$headers = 'From: [email protected]'. "\r\n";
$headers.= 'CC: '. $cc. "\r\n";
$headers.= 'Subject: '. $subject. "\r\n";
// Send the email
mail($to, $subject, $message, $headers);
?>
In this example, the cc
variable is set to the email address of the CC recipient. The headers
variable is then updated to include the CC
header with the CC recipient's email address.
You can also use the additional_headers
parameter when calling the mail()
function to add the CC recipient. Here's an example:
<?php
$to = '[email protected]';
$subject = 'Test email';
$message = 'This is a test email';
// Add CC recipient
$cc = '[email protected]';
// Send the email
mail($to, $subject, $message, null, 'From: [email protected]'. "\r\nCC: ". $cc. "\r\n");
?>
In this example, the additional_headers
parameter is used to add the CC
header with the CC recipient's email address.
Note that the cc
parameter is only supported in PHP 5.3 and later versions. In earlier versions of PHP, you can use the additional_headers
parameter to add the CC recipient.