Dear programming cracks!
I set up a website and thought an email form would be nice, but I thought it would be easier to get it right!
I got it quite ok with the easy example below which I found at:
http://www.freewebmasterhelp.com/tutorials/php/6
<?
function checkOK($field)
{
if (eregi("\r",$field) || eregi("\n",$field)){
die("Invalid Input!");
}
}
$name=$_POST['name'];
checkOK($name);
$email=$_POST['email'];
checkOK($email);
$comments=$_POST['comments'];
checkOK($comments);
$to="php@gowansnet.com";
$message="$name just filled in your comments form. They said:\n$comments\n\nTheir e-mail address was: $email";
if(mail($to,"Comments From Your Site",$message,"From: $email\n")) {
echo "Thanks for your comments.";
} else {
echo "There was a problem sending the mail. Please check that you filled in the form correctly.";
}
?>
I adapted it slightly with fields and a check for needed input fields.
I copied and adapted these lines from another script:
if (empty($email) || (empty($name)) || (empty($comments))) {
echo "There was an error! Please go back and check that you filled in the required fields.";
exit ;
So far it works quite well.
Except for -
It occured quite a few times that I got to the error page "Invalid Input!" because of those very first lines when I typed text in the comments field.
It seems to filter out too much and I don't understant what those first lines exactly do. On the site I copied thise from it said it was there to prevent spammers to use my php and mail function...
On one hand I want my script to be rather safe against spamming of course, on the other you should be able to type normally your message without resulting in an error message.
If you could help, I'd be very glad! :)
I wanted to concentrate on my page and content, now I'm spending days with that form mail! *sigh*
Cheers,
Dominique