I'm using the code below for the messages sent via the contact form of my website. The issue is that all the messages arrive in the spam box.
I suspect that this is because of this part "From:" . $_POST['email']
What are your thoughts on this issue?
Thanks,
<?php
// Email Submit
// Note: filter_var() requires PHP >= 5.2.0
if ( isset($_POST['email']) && isset($_POST['name']) && isset($_POST['message']) && filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) ) {
// detect & prevent header injections
$test = "/(content-type|bcc:|cc:|to:)/i";
foreach ( $_POST as $key => $val ) {
if ( preg_match( $test, $val ) ) {
exit;
}
}
//send email
mail( "XYZ****@hotmail.com", "New message from: ".$_POST['name'], $_POST['message']."\nFrom page: ". str_replace("http://", "", $_SERVER['HTTP_REFERER']), "From:" . $_POST['email'] . "\r\n" . "BCC: ABC****@gmail.com" );
}
?>