I been trying to create a form that allows user to send information to my email, but only about 50% of the time that the data actually comes through. Is it something within the PHP or regarding to the email service I'm sending the data to?
<?php
$name = $_POST['q1'];
$visitor_email = $_POST['q2'];
$interest = $_POST['q3'];
$current = $_POST['q3.5'];
$designer = $_POST['q4'];
$link = $_POST['q5'];
//Validate first
if(empty($name)||empty($visitor_email))
{
echo "Name and email are missing!";
exit;
}
if(IsInjected($visitor_email))
{
echo "Bad email value!";
exit;
}
$email_from = 'username@gmail.com';
$email_subject = "Application Submission";
$email_body = "You have received a new message from the user $name.\n".
"Email: $visitor_email.\n".
"Interest: $interest.\n".
"Design: $designer.\n".
"Link: $link.\n".
$to = 'username@gmail.com';
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
mail($to,$email_subject,$email_body,$headers);
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;
}
}
?>