| | |
Contact Form Spam
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Sep 2008
Posts: 2
Reputation:
Solved Threads: 0
I have a website that I just created a contact form for. However. it seems like a bot has hit the form, and continously fills out emails. I don't know php very well - and someone else did most of the work.
I don't want to put a captcha in, as it reduces the amount of people that will fill out the form. Instead, I'd like to make a "do or die" code that requires the user to fill out a phone number.
Here's the current code. What should I do to fix it?
I don't want to put a captcha in, as it reduces the amount of people that will fill out the form. Instead, I'd like to make a "do or die" code that requires the user to fill out a phone number.
Here's the current code. What should I do to fix it?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Sendemail Script</title>
</head>
<body>
<!-- Reminder: Add the link for the 'next page' (at the bottom) -->
<!-- Reminder: Change 'YourEmail' to Your real email -->
<?php
$ip = $_POST['ip'];
$httpref = $_POST['httpref'];
$httpagent = $_POST['httpagent'];
$visitormail = $_POST['email'];
$comments = $_POST['comments'];
$case_description = $_POST['case_description'];
$phone = $_POST['phone'];
$street = $_POST['address'];
$yourname = $_POST['name'];
$todayis = date("l, F j, Y, g:i a") ;
$subject = $attn;
$notes = stripcslashes($notes);
$message = " $todayis [EST] \n
From: $yourname ($visitormail)\n
Phone Number: $phone \n
Address: $street \n
Comments: $comments \n
Case Description: $case_description \n
Additional Info : IP = $ip \n
Browser Info: $httpagent \n
Referral : $httpref \n
";
$from = "From: $visitormail\r\n";
mail("jcernamonroe@yahoo.com", "Contact Info from Exclusively Criminal Deffense", $message, $from);
?>
<p align="center">
<SCRIPT LANGUAGE="JavaScript">
window.location="../success.html";
</script>
</body>
</html> The phone number is a good idea as a spam bot probably won't fill that in correct, especially if we validate it. 
This method will accept a 10 digit phone number with spaces, dashes, or neither.

This method will accept a 10 digit phone number with spaces, dashes, or neither.
PHP Syntax (Toggle Plain Text)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Sendemail Script</title> </head> <body> <!-- Reminder: Add the link for the 'next page' (at the bottom) --> <!-- Reminder: Change 'YourEmail' to Your real email --> <?php $ip = $_POST['ip']; $httpref = $_POST['httpref']; $httpagent = $_POST['httpagent']; $visitormail = $_POST['email']; $comments = $_POST['comments']; $case_description = $_POST['case_description']; $phone = $_POST['phone']; $street = $_POST['address']; $yourname = $_POST['name']; $todayis = date("l, F j, Y, g:i a") ; $subject = $attn; $notes = stripcslashes($notes); $message = " $todayis [EST] \n From: $yourname ($visitormail)\n Phone Number: $phone \n Address: $street \n Comments: $comments \n Case Description: $case_description \n Additional Info : IP = $ip \n Browser Info: $httpagent \n Referral : $httpref \n "; $from = "From: $visitormail\r\n"; if (!preg_match('/^\d{3}[\s-]?\d{3}[\s-]?\d{4}$/', $phone)) { echo 'The phone number you provided was invalid.'; } else { mail("jcernamonroe@yahoo.com", "Contact Info from Exclusively Criminal Deffense", $message, $from); ?> <p align="center"> <SCRIPT LANGUAGE="JavaScript"> window.location="../success.html"; </script> <?php } ?> </body> </html>
Last edited by MVied; Sep 16th, 2008 at 6:47 pm.
You can install latest captcha as well.
![]() |
Similar Threads
- PHP Contact form (PHP)
- Avoiding Spam from sendmail.php (Promotion and Marketing Plans)
- New to php and need some help with a guestbook (PHP)
- Having prolems with a guestbook (HTML and CSS)
- Contact form without scipts (PHP)
- Setting a Session Cookie (PHP)
- Help with asp form will not display contact information (ASP)
Other Threads in the PHP Forum
- Previous Thread: Store pics in database
- Next Thread: Static URL to Dynamic URL
| Thread Tools | Search this Thread |
ajax apache api array arrays beginner binary broken cache cakephp checkbox class cms code confirm cron curl customizableitems database date display dynamic echo email error external file files folder form forms forum function functions google header headmethod howtowriteathesis href htaccess html iframe image include insert integration ip java javascript joomla limit link login loop mail malfunction menu method mlm multiple mysql neutrality oop paypal pdf php phpmysql play problem query question radio random recursion regex remote root script search select server sessions sms soap source space sql syntax system table tutorial update upload url validator variable video web xml youtube






