I'd greatly appreciate any advise on how to fix this short email validation script. At the bottom of the code, I've included the script that successfully sends me an email when I enter the correct email-address. When I insert it into the above script, the page that I'm sending it from goes blank when I hit the submit button, and no email is sent... nor do any of the echo messages that I've inserted pop up.
Should I perhaps be using something other than FILTER_SANITIZE_EMAIL and FILTER_VALIDATE_EMAIL?
Thank you.
<?php
if(isset($_POST['submitEmail'])) {
if (!spamcheck($_REQUEST['submitEmail'])) {
echo "Invalid input";
} else { //EVERYTHING INSIDE THIS TAG HAS TESTED OK ON ITS OWN
$email_to = "jemartinsen@gmail.com";
$email_from = $_REQUEST['email'];
$name_from = $_REQUEST['name'];
$subject = "This is a subject";
$message = $_REQUEST['message'];
$headers = "From: $name_from <$email_from>\n" .
"Return-Path: $email_from\n" .
"MIME-Version: 1.0\n" .
"Content-Type: Content-type: text/html; charset=iso-8859-1\n";
mail($email_to, $subject, $message, $headers);
echo "<script>alert('Your message has been successfully delivered.');</script>";
} //END SCRIPT THAT HAS TESTED OK ON ITS OWN
}
function spamCheck($field) {
$field = filter_var($field, FILTER_SANITIZE_EMAIL);
if (filter_var($field, FILTER_VALIDATE_EMAIL)) {
echo "Spamcheck ok!";
return true;
} else {
echo "Spamcheck failed!";
return false;
}
}
?>
//THIS PART IS CONFIRMED AS WORKING ON ITS OWN, I RECIEVE MAIL USING IT
<?php
if($_POST['submitEmail']) {
$email_to = "jemartinsen@gmail.com";
$email_from = $_REQUEST['email'];
$name_from = $_REQUEST['name'];
$subject = "This is a subject";
$message = $_REQUEST['message'];
$headers = "From: $name_from <$email_from>\n" .
"Return-Path: $email_from\n" .
"MIME-Version: 1.0\n" .
"Content-Type: Content-type: text/html; charset=iso-8859-1\n";
mail($email_to, $subject, $message, $headers);
echo "<script>alert('Your message has been successfully delivered.');</script>";
}
?>
MOD EDIT: No need to link to pastebin... just include the PHP code in your post (along with the [noparse]
[/noparse] bbcode tags).