I’m using the code below to send emails via a contact form. Issue is that the emails go to the spam box every time (in outlook, gmail, etc). I suspect that this due to the fact that there’s a url (the web page URL) in the body of the e-mail. Therefore I was wondering if there’s some workaround (apart for tagging these emails as non-spam in gmail and outlook) in order to keep the URL (I want to keep it) but have the emails not considered as spam. Maybe by re-constructing the URL so that it does not look like a URL? Surely big companies have tips & tricks for that? Many 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( "dsfds@sfss.com", "Nouveau message de: ".$_POST['name'], $_POST['message'] ."\n From site: ". $_SERVER['HTTP_REFERER']., "From:" . $_POST['email'] . "\r\n" . "BCC: dsfds@gmail.com" );
}
?>
Send headers with it, like this: