I have a problem to send cc in php mail function to get feedback from the client. Here is a simple php code-
<?php
if(isset($_POST["submit"])){
// Checking For Blank Fields..
if($_POST["name"]==""||$_POST["email"]==""||$_POST["sub"]==""||$_POST["msg"]==""){
echo "Fill All Fields..";
}else{
// Check if the "Sender's Email" input field is filled out
$email=$_POST['email'];
// Sanitize E-mail Address
$email =filter_var($email, FILTER_SANITIZE_EMAIL);
// Validate E-mail Address
$email= filter_var($email, FILTER_VALIDATE_EMAIL);
if (!$email){
echo "Invalid Sender's Email";
}
else{
$subject = $_POST['sub'];
$name = $_POST["name"];
$message = $_POST['msg'];
$headers = 'From:'. $email . "\r\n"; // Sender's Email
$headers .= 'Cc:'. $email . "\r\n"; // Carbon copy to Sender
// Send Mail By PHP Mail Function
mail("xyz@example.com", $subject, $message, $headers);
echo "Your mail has been sent successfuly !";
}
}
}
?>
The mail is sent to the sender correctly but cc is not sent. Moreover when I fixed the email address in the Cc field i.e abc@xxx.com instead of $email, then Cc works. Help me to solve the problem.