I’m trying this out on a form that’s been getting hit by a dirty rotten spammer lately. I expect it’ll do the trick. Thanks for posting it!
I actually added a separate check to the function to block messages with certain words in them. I did this mostly because I thought that perhaps this spambot had already determined which field data it needed to send to this form and wouldn’t necessarily recheck it and fill in the hidden field. I wanted to be sure that I stopped the current wave of spam, and this seemed like a simple way to do it.
<?php
function antiSpam(&$fields,&$vMsg,&$rMsg) {
$hasBadWords='no';
$badWords=array('xanax','viagra','phentermine','cialis','tramadol','propecia','[url=');
foreach($badWords as $badWord){
if(strpos(strtolower($fields['Name']),$badWord) !== false) $hasBadWords='yes';
if(strpos(strtolower($fields['emailSubject']),$badWord) !== false) $hasBadWords='yes';
if(strpos(strtolower($fields['message']),$badWord) !== false) $hasBadWords='yes';
}
if(!empty($fields['Last__Name'])||$hasBadWords=='yes') {
return false;
} else {
return true;
}
}
?>
I don’t think that any legitimate email would ever have any of these words in it, so it seems like a safe extra measure to throw into the mix.