Adding 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]';

// Send the email
mail($to, $subject, $message, 'From: [email protected]', 'CC: '. $cc);
?>

In this example, the mail() function is called with the following parameters:

Note that the CC parameter is added as a string, and it should be formatted as CC: <email_address>. You can add multiple CC recipients by separating their email addresses with commas.

Alternatively, you can use the additional_headers parameter to add custom headers to the email, including 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
$headers = 'From: [email protected]'. "\r\n";
$headers.= 'CC: '. $cc. "\r\n";
mail($to, $subject, $message, $headers);
?>

In this example, the additional_headers parameter is used to add a custom header to the email. The header is formatted as CC: <email_address>, and it includes the CC recipient's email address.

Both of these examples will send an email with a CC recipient. However, keep in mind that the mail() function is not always reliable, and it may not work as expected in all situations. It's always a good idea to use a more robust email library or service to send emails in your PHP application.