I'm currently using the following a PHP code sample given on the web on my website to receive e-mails where visitors use a form and it sends to this php file.
On my HTML web form I have been using a vcode field (validation code) where the user must enter a validation code to be able to send the form. I have started doing this because of those malicious bots on the web that keep using the form over and over again to send me dozens of viagra e-mails a day. However, those bots are so intelligent they can bypass the vcode and it sends me an e-mail with all the fields filled except for vcode set to unknown. So, I'd like to modify this code to reject every mail where the vcode = unknown.
I know here the $val = stripslashes($val); strips every text field from the HTML, and one of them will have the vcode. It is only a matter of checking if vcode = unknown then discard e-mail (do not send it). Of course, I'm a complete newbie to PHP, but I suppose the fix here is a single line :') (or two)
In the code, I have replaced the e-mail addresses, subject, and confirmation HTML with generic ones.
Thank you in advance for your help.
=== Start of code ==
[FONT=Courier New]
<HTML>
<BODY>
<font face=verdana size=2>
<?php
if ($_SERVER['REQUEST_METHOD']=="POST"){
$msg="Your message:\n\n";
foreach($_POST as $key => $val){
if (is_array($val)){
$msg.="Item: $key\n";
foreach($val as $v){
$v = stripslashes($v);
$msg.=" $v\n";
}
} else {
$val = stripslashes($val);
$msg.="$key: $val\n";
}
}
error_reporting(1);
$recipient = "first@email.com, [email]second@email.com[/email], [email]third@email.com[/email]";
$subject = "Mail subject";
if (mail($recipient, $subject, $msg)){
echo " ";
?>
<SCRIPT LANGUAGE=JavaScript><!--
top.location.href = "http://address.that.confirms.that.mail.is.sent/confirmation.html";
//--></SCRIPT>
<?php
} else
echo " ";
} else
echo " ";
?>
</font>
</BODY>
</HTML>[/FONT]
== End of code ==