-1

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\n";
$email_content .= "Email:  $email\n\n";
$email_content .= "Phone:  $phone\n\n";
$email_content .= "Message:  $message\n";
$email_content .= "$subscribe: Yes\n";

// 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.";
} 
Nisarg
  • 1,631
  • 6
  • 19
  • 31

1 Answers1

1

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>\n";
$email_headers .= "BCC: xy123@gmail.com";
Andreas
  • 23,610
  • 6
  • 30
  • 62