I want to send BCC email along with Recipient in Contact form. How I can include BCC in my code? I am not seeing error in below code but it won't send you email to BCC or Recipient. If I remove BCC, it will send you to Recipient.
$recipient = "xjkfak223@gmail.com";
// Set the email subject.
$subject = "New contact from $name";
// Build the email content.
$email_content = "Name: $name
";
$email_content .= "Email: $email
";
$email_content .= "Phone: $phone
";
$email_content .= "Message: $message
";
$email_content .= "$subscribe: Yes
";
// Build the email headers.
$email_headers = "From: $name <$email>";
$email_headers = "BCC: xy123@gmail.com";
// Send the email.
if (mail($recipient, $subject, $email_content, $email_headers)) {
// Set a 200 (okay) response code.
http_response_code(200);
echo "Thank You for Contacting Us.";
}
You're overwriting the variable.
If you add .=
it will append the string. I suppose you need a comma new line between too.
$email_headers = "From: $name <$email>
";
$email_headers .= "BCC: xy123@gmail.com";