Forum Moderators: coopster
I have a PHP contact form script on my site with the email address a variable and not visible on the page. I am no programmer and got the script from a free script site (see below)
<?php
$headers .= "From: $name <$theiraddr>\n";
$headers .= "Content-Type: text/plain; charset=iso-8859-1\n"; // sets the mime type
$recipient = "emailaddresshere";
$subject = "Website Enquiry";
$msg = wordwrap( $msg, 1024 );
mail($recipient, $subject, stripslashes($msg), $headers);
header("location: thanks.html");
?>
Everything was going well until recently when a robot keeps filling out the form, posting giberrish and costing me bandwidth.
So I did a bit of hunting around and found a javascript validation extension for dreamweaver that makes the user fill out all fields, thinking that this will deter the robot.
Things got worse!
I wondered if anybody on here could suggest
1. A way to stop this robot
2. A way to identify these robots (is their a directory of them somewhere?)
Any advice would be welcomed
simple solution: if you are on a linux server and using Cpanel site control panel, you can ban any visitor from that IP address to see stuff on your site.
slightly complex solution: use access control methods using .htaccess to ban any activity from that IP (individual or block level)
HTH
JLS
The way it is done is to try to add a carriage return (\r) or newline (\n) to the form field and insert the Bcc: field. Modify your script to strip out any \r or \n entered. For php, you may do it thus:
<?php
$from=$_POST["sender"];
if (eregi("\r",$from) ¦¦ eregi("\n",$from)){
die("Yet another spam attempt thwarted!");
}
?>
Hope that helps.
So read all the threads on the forums, and take your precautions. One simple solutions is to hardcode your headers. Don't put any POST vars in them. Filter the $from or $email vars and place them in the body of the email.
I will now expose my complete coding ineptitude by posting my script changes. If any body could tell me of any schoolboy errors, again, I would be most grateful
<?php
$headers .= "From: $name <$theiraddr>\n";
$headers .= "Content-Type: text/plain; charset=iso-8859-1\n"; // sets the mime type
$recipient = "myemail@myemail";
$subject = "Website Enquiry";
$msg = wordwrap( $msg, 1024 );
$headers .= "From: $name <$theiraddr>\n";
$headers .= "Content-Type: text/plain; charset=iso-8859-1\n";
$recipient = "myemail@myemail";
$subject = "Website Enquiry";
$from=$_POST["sender"];
if (eregi("\r",$from) ¦¦ eregi("\n",$from)){
die("Yet another spam attempt thwarted!");
}
$msg = wordwrap( $msg, 1024 );
mail($recipient, $subject, stripslashes($msg), $headers);
header("location: thanks.html");
mail($recipient, $subject, stripslashes($msg), $headers);
?>
(sorry if this offends any programmers!)