formmail.php - hidden field in form - when field is filled, spam detection kicks in

I thought this was already built into formmail.php - i'm want to enter a hidden field to my form using so if it's filled out the form will not submit but instead redirect to a spam error page. something like this:

$Comments = $_POST['Comments'];
if ($Comments != '') {
exit("Thanks for your input Spammy");
} else {

// Send the mail using PHPs mail() function
mail($to, $subject, $message, $headers);

// Redirect
header("Location: thanks.htm");
}

but i thought this logic was already built into formmail.php?
phillystyle123Asked:
Who is Participating?
 
Ray PaseurCommented:
There may not be native support for a captcha, but it is very easy to implement.
<?php // RAY_captcha_in_action.php
error_reporting(E_ALL);

// IF ANYTHING WAS POSTED
if (!empty($_POST))
{
    // TEST THE STRINGS
    if ($_POST["_newMd5"] != md5($_POST["_newCode"]))
    {
        // MIGHT WANT TO MAKE THIS USER-FRIENDLY
        echo 'SECURITY CODE NUMBER DID NOT MATCH';
    }
    else
    {
        echo "SUCCESS!";
    }
}
// END OF PHP - PUT UP THE FORM
?>
<form method="post">
<!-- STYLE THIS TO SUIT YOUR PAGE STYLE -->
Type <img style="display:inline;" src="RAY_captcha_image.php?dt=<?php $x = mt_rand(1000,10000); echo base64_encode($x); ?>" /> here:
<input name="_newCode" type="text"   maxlength="64" size="6" autocomplete="off" />
<input name="_newMd5"  type="hidden" value="<?php echo md5($x); ?>" />
<input type="submit" />
</form>

Open in new window

<?php // RAY_captcha_image.php
error_reporting(E_ALL ^ E_NOTICE);


// GENERATES A PICTURE OF A NUMBER INTO THE BROWSER OUTPUT


// DECODE THE INCOMING STRING
$data = base64_decode($_GET['dt']);

// CREATE AN IMAGE RESOURCE - CHOOSE THE SIZE THAT BEST MATCHES YOUR PAGE STYLE
$im = imagecreate(46,13);

// WHITE BACKGROUND
$bg = imagecolorallocate($im, 255,255,255);

// GRAY STRIPES
$gray = imagecolorallocate($im, 188,188,188);

// FIREBRICK TEXT
$text = imagecolorallocate($im, 178,34,34);

// ADD THE NUMBER TO THE IMAGE
imagestring($im,5,4,0,$data,$text);

// WRITE A GRAY STRIPE (OR MORE IF YOU CHOOSE)
imageline($im,4,12,38,0,$gray);

// SEND THE IMAGE INTO THE BROWSER OUTPUT STREAM
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);

Open in new window

0
 
Dave BaldwinFixer of ProblemsCommented:
Here is the current doc page for PHPFormail http://developerkarma.com/projects/phpformmail/readme-all-one-version

I don't see anything that does what you're asking.
0
 
Ray PaseurCommented:
Add a captcha image to the form.  Put it last, right before the submit button.  Much safer than trying to guess if the form was filled in by a 'bot.
0
 
Dave BaldwinFixer of ProblemsCommented:
I don't think PHPFormail supports Captcha either.
0
 
phillystyle123Author Commented:
THANKS RAY
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.