Hi, i looking for a simple contact form, something like this: Name: E-mail: Message: after the client click on the "send" button i receive a e-mail with the name/e-mail/message
Make a new file in PHP , maybe contact.php and Paste this: <?php if ($_POST){ $to = "[B]youremail@gmail.com[/B]"; $subject = "[B]YOUR SUBJECT[/B]"; $email = $_REQUEST["email"]; $name = $_REQUEST["name"]; $message = "Name: ".$name."\r\n". "Email: ".$email."\r\n". "Message: ".$_REQUEST["message"]; $headers = "From: $email"; mail($to, $subject, $message, $headers); echo "Thanks for submitting."; }else{ ?> <html> <head> <title>Contact Us</title> <body> <form action='[B]contact.php[/B]' method='post'> <tr> <td> Your Name: <input type='text' name='name'><br> </td> <td> Your Email: <input type='text' name='email'><br> </td> <td> Message: <textarea name='message'></textarea><br> </td> </tr> <input type='submit' value='Send comments'> </form> </body> </html> <?php } ?> Code (markup): Don't Forget to change text above in Bold. Make sure your server contains PHP with MAIL function enabled. Thanks
Question - what is the best way to prevent spam bots from submitting spam messages on a simple form like the above? I know I can use JavaScript validation but the spam bots are clever enough to get around that. I guess I would have to use server-side validation - what is the most effective method to use?
why not program a cookie around it that only lets the user send an e-mail from their computer around every 12 hours? or consider storing their IP in a database and the time the last email was sent... basically the same principle
Yeah you can turn off JS so your JS check wont work if that happens. Captcha is a good way to deter from spamming. Data wise make sure you clean it up, if the field shouldnt accept html code then strip it. If the entry is suppose to be a number only then make sure its just a number. I had to go through all this when they used the mcafee scanner to test for any vulnerabilities on the website. Also if you need more functionality with email form check out PHPMailer.
You can make a simple form with ease using 123ContactForm web form maker service. Design your form there, put the HTML code on your website and once a visitor of yours fills that form, all that data will be delivered to your inbox.