Question

I'm trying to BCC an email in my PHP form. For some reason, the following code isn't sending the form to the BCC address:

$headers = "From: " . strip_tags($from) . "\r\n" . "BCC:test@test.com";
$headers .= "Reply-To: ". strip_tags($from) . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

Apart from the BCC not receiving the email, the form works. For the BCC part, I used the accepted answer at: Add BCC field to a php contact form

Any help is appreciated.

Was it helpful?

Solution

Your BCC is not delimited by \r\n and so the reply-to header is joined to the BCC value (making it invalid).

The mail server is seeing the BCC header as:

BCC:test@test.comReply-to: xxx@example.com

Change to:

$headers = "From: " . strip_tags($from) . "\r\n" . "BCC:test@test.com\r\n";

Side note: strip_tags() is not enough to protect against a header injection attack. You must validate the from email address properly.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top