I have a contact form in my website, using the php below to delivery the form result as email.
My problem is that whenever someone uses the contact form, I receive the email as spam, instead of the normal inbox folder. Could the problem be in the php above?PHP Code:<?php
if(!isset($_POST['send']))
{
//Need to submit the form.
echo "error; you need to submit the form!";
}
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$message = $_POST['message'];
//Validate first.
if(empty($name)||empty($visitor_email))
{
echo "Your Name and Email is required, please try again!";
exit;
}
if(IsInjected($visitor_email))
{
echo "Bad email value!";
exit;
}
$email_from = 'silas@sicdesigns.info';//<== this websites email, I shall update this when we get the domain name.
$email_subject = "New Form Submission SiC";
$email_body = "You have received a new quick message from $name.\n\n".
"Here is the message:\n
From: $visitor_email\n\n
$message\n\n".
$to = "sicdesigz@gmail.com";//<== where it will send the message to, let me use my email for now.
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
//Send the email!
mail($to,$email_subject,$email_body,$headers);
//done. redirect to thank-you page.
header('Location: thank-you.html');
// Function to validate against any email injection attempts
function IsInjected($str)
{
$injections = array('(\n+)',
'(\r+)',
'(\t+)',
'(%0A+)',
'(%0D+)',
'(%08+)',
'(%09+)'
);
$inject = join('|', $injections);
$inject = "/$inject/i";
if(preg_match($inject,$str))
{
return true;
}
else
{
return false;
}
}
?>


Reply With Quote

Bookmarks