Bcc and cc mail in php

In PHP, you can use the mail() function to send emails with BCC (blind carbon copy) and CC (carbon copy) recipients. Here's an example of how to do it:

BCC (Blind Carbon Copy)

To send an email with BCC recipients, you can use the BCC parameter in the mail() function. The BCC parameter takes an array of email addresses as its value.

Here's an example:

$to = '[email protected]';
$bcc = array('[email protected]', '[email protected]');

$headers = 'From: [email protected]'. "\r\n".
           'Reply-To: [email protected]'. "\r\n".
           'MIME-Version: 1.0'. "\r\n".
           'Content-Type: text/plain; charset=UTF-8';

$message = 'This is a test email';

mail($to, 'Test Email', $message, 'BCC: '. implode(',', $bcc), $headers);

In this example, the email will be sent to [email protected] with the BCC recipients [email protected] and [email protected].

CC (Carbon Copy)

To send an email with CC recipients, you can use the CC parameter in the mail() function. The CC parameter takes an array of email addresses as its value.

Here's an example:

$to = '[email protected]';
$cc = array('[email protected]', '[email protected]');

$headers = 'From: [email protected]'. "\r\n".
           'Reply-To: [email protected]'. "\r\n".
           'MIME-Version: 1.0'. "\r\n".
           'Content-Type: text/plain; charset=UTF-8';

$message = 'This is a test email';

mail($to, 'Test Email', $message, 'CC: '. implode(',', $cc), $headers);

In this example, the email will be sent to [email protected] with the CC recipients [email protected] and [email protected].

Note: When using BCC or CC, make sure to separate the recipients with commas (,) and enclose the entire list in quotes (") or parentheses (()).

Also, keep in mind that the mail() function is a low-level function and may not work as expected in all environments. It's recommended to use a PHP email library or framework that provides a more robust and flexible way of sending emails.