Skip to content
PHP Logo

How can the code be modified to send separate emails to the recipient and CC (Carbon Copy) for a more professional appearance?

To send separate emails to the recipient and CC for a more professional appearance, you can modify the PHP code to include the recipient's email in the "To" field and the CC email in the "Cc" field of the email headers. This way, the recipient will receive the email directly, while the CC recipient will receive a copy for reference.

php
$to = 'recipient@example.com';
$cc = 'cc@example.com';
$subject = 'Subject of the email';
$message = 'Content of the email';

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

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

if ($mail_sent) {
    echo 'Email sent successfully.';
} else {
    echo 'Error sending email.';
}