/    Sign up×
Community /Pin to ProfileBookmark

Validating an email

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.

[URL=”http://pastebin.com/m6536ba84″]http://pastebin.com/m6536ba84[/URL]

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@Phill_PaffordJun 20.2008 — [code=php]
#
<?php

if(isset($_POST['submitEmail'])) {
if (!spamcheck($_REQUEST['submitEmail'])) {
echo "<script>alert('Invalid input.');</script>";
} else {
$email_to = "[email protected]";
$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_fromn" .
"MIME-Version: 1.0n" .
"Content-Type: Content-type: text/html; charset=iso-8859-1n";
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;
}
}
?>
[/code]
Copy linkTweet thisAlerts:
@IanMartinsauthorJun 20.2008 — 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.
Copy linkTweet thisAlerts:
@Phill_PaffordJun 20.2008 — 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
Copy linkTweet thisAlerts:
@bokehJun 20.2008 — 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.[/QUOTE]That means you have a parse error in your code and error reporting is switched off.
×

Success!

Help @IanMartins spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...