I saw this tip on another web site to prevent spam on contact forms. In the contact form you add a hidden field
And then in the PHP file you add
if ( $_POST['to_address'] ) { echo 'Tastes Like spam!'; } else {...send email...}
But my PHP file is a little different as also activates some JavaScript on the webpage depending on whether the form is filled out correctly or not (If successful shows a little ?Your email has been sent...? with animation. If the fields aren?t filled out correctly it shows what?s missing).
Someone else made the contact form for me as I don?t know any PHP (or ajax), but I?ve tried to adapt the code above & add it to my PHP form. I?ve tested it & it seems to work OK, but thought I?d just check that it shouldn?t potentially cause any problems, or if it needs tweaking/formatting a little.
Here?s the last part of my original PHP file
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";
$success = true; mail($EmailTo, $Subject, $Body, "From: <$Email>");
}
// call success or error js functions
if ($success){
print "doThanks()";
}
else{
print "doError()";
}
?>
And here it is after I added the (hopefully) anti spam code
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";
$success = true; mail($EmailTo, $Subject, $Body, "From: <$Email>");
}
// call success or error js functions
if ( $_POST['to_address'] ) { echo 'Tastes Like spam!'; } else
if ($success){
print "doThanks()";
}
else{
print "doError()";
}
?>
Does the code I added look OK, or does it need changing in any way?