Click to See Complete Forum and Search --> : Validating an email
IanMartins
06-20-2008, 05:54 AM
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, and no email is sent... nor do any of the alert messages that I've inserted pop up.
Should I perhaps be using something other than FILTER_SANITIZE_EMAIL and FILTER_VALIDATE_EMAIL?
Thank you.
http://pastebin.com/m6536ba84
Phill Pafford
06-20-2008, 06:56 AM
#
<?php
if(isset($_POST['submitEmail'])) {
if (!spamcheck($_REQUEST['submitEmail'])) {
echo "<script>alert('Invalid input.');</script>";
} else {
$email_to = "mail@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>";
}
}
else
{
echo "NOT SET<br />"; // Check to see if val is set
}
function spamCheck($field) {
$field = filter_var($field, FILTER_SANITIZE_EMAIL);
if (filter_var($field, FILTER_VALIDATE_EMAIL)) {
echo "<script>alert('Spamcheck ok.');</script>";
return true;
} else {
echo "<script>alert('Spamcheck failed.');</script>";
return false;
}
}
?>
IanMartins
06-20-2008, 07:24 AM
Thanks, I appreciate your time, but there's no difference.
My main page is called index.php, and it has an require() tag that links to functions.php, where I store the email/validation script for now.
The form-tag calls upon the page (index.php) to reload itself when the form is submitted, something it does when I use PHP to successfully send an email. As soon as I enter any validation code into functions.php however, the page goes blank when I hit submit, and no email is sent. You can test this yourself, at www.objectisoft.com.
Phill Pafford
06-20-2008, 07:34 AM
I would check your error logs to see what the error is. you can fin it in this dir
/var/log/httpd/error_log
most of the time
bokeh
06-20-2008, 08:45 AM
When I insert it into the above script, the page that I'm sending it from goes blank, and no email is sent... nor do any of the alert messages that I've inserted pop up.That means you have a parse error in your code and error reporting is switched off.