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?

<!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>

Recommended Answers

All 2 Replies

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.

<!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>

You can install latest captcha as well.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.