I have a new web form that I am testing, and I am getting two e-mails every time the form is submitted. Can someone please take a look at my PHP code to see if there's something in there that's causing the double e-mail? Thank you.
PHP Code:
<?php
if(!isset($_POST['submit']))
{
//This page should not be accessed directly. Need to submit the form.
echo "error; you need to submit the form!";
}
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$visitor_email = $_POST['visitor_email'];
$phone = $_POST['phone'];
$emailcheckbox = $_POST['emailcheckbox'];
$phonecheckbox = $_POST['phonecheckbox'];
$fafsacheckbox = $_POST['fafsacheckbox'];
$cssprofilecheckbox = $_POST['cssprofilecheckbox'];
$verificationcheckbox = $_POST['verificationcheckbox'];
$tapcheckbox = $_POST['tapcheckbox'];
$loanassistancecheckbox = $_POST['loanassistancecheckbox'];
$consultationcheckbox = $_POST['consultationcheckbox'];
$nassau = $_POST['nassau'];
$suffolk = $_POST['suffolk'];
$borough = $_POST['borough'];
$learn = $_POST['learn'];
$comments = $_POST['comments'];
//Validate first
if(empty($firstname)||empty($visitor_email))
{
echo "Name and e-mail address are mandatory!";
exit;
}
if(IsInjected($visitor_email))
{
echo "Bad email value!";
exit;
}
$email_from = 'Contact@FinancialAidFiler.com';//<== update the email address
$email_subject = "FinancialAidFiler.com E-Mail Inquiry";
$email_body = "Name: $firstname $lastname.\n".
$email_visitor_email = "E-Mail: $visitor_email.\n".
$email_phone = "Phone Number: $phone.\n".
$email_emailcheckbox = "Contact Preference: $emailcheckbox\n".
$email_phonecheckbox = "Contact Preference: $phonecheckbox.\n".
$email_fafsacheckbox = "Interested In: $fafsacheckbox.\n".
$email_cssprofilecheckbox = "Interested In: $cssprofilecheckbox.\n".
$email_verificationcheckbox = "Interested In: $verificationcheckbox.\n".
$email_tapcheckbox = "Interested In: $tapcheckbox.\n".
$email_loanassistancecheckbox = "Interested In: $loanassistancecheckbox.\n".
$email_consultationcheckbox = "Interested In: $consultationcheckbox.\n".
$email_nassau = "Nassau County: $nassau.\n".
$email_suffolk = "Suffolk County: $suffolk.\n".
$email_borough = "Borough: $borough.\n".
$email_learn = "How Did You Learn About Us?: $learn.\n".
"Comments:\n $comments".
$to = "Contact@FinancialAidFiler.com";//<== update the email address
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
//Send the email!
mail($to,$email_subject,$email_body,$headers,$town);
//done. redirect to ThankYou page.
header('Location: ThankYou.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;
}
}
?>
Actually, I am getting three e-mails.
The form is located here: http://www.financialaidfiler.com/Form/Form-Page.html
Bookmarks