Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

captcha

Featured Replies

i have a contact for on my site a recently been getting spammed. This became very bad last night with 54 emails from the same spam bot in 1 hour!!!

 

ive disabled my contact form at the moment.

 

im looking to add a captcha to it to stop these bots. can any help or recogmend a free one to add to my contact form. tried a feu but cant get them to work :S

 

here is my contact.php page

 

	<?php include("includes/top.php"); ?> 

 <title>Contact Us</title>

<?php include("includes/keywords.php"); ?> 
<?php include("includes/header.php"); ?> 

<?php include("includes/nav.php"); ?>
<?php include("includes/colum.php"); ?>


<div id="content">

	<h2>Conact Us</h2>

	<p>Fill out the form below and we will contact you ASAP</p>

<div id="formcontainer">

	<script type="text/javascript">
		<!--

		function checkMailto(theForm) {
		if (theForm.name.value=="") {
		alert("Please enter your name");
		theForm.name.focus();
		return false;
		}
		if (theForm.tel.value=="") {
		alert("Please enter your telephone number");
		theForm.tel.focus();
		return false;
		}
		if (theForm.email.value=="") {
		alert("Please enter a valid email address");
		theForm.tel.focus();
		return false;
		}

		return true;
		}
		//-->
	</script>

	<form action="sendmail.php" name="mailForm" method="post" onSubmit=" return checkMailto(this);">


		  <div class="clearfix">
		<label>Your Name:</label>
 			<input name="name" type="text" size="34" />
			</div>

		  <div class="clearfix">
 		<label>Your Address:</label>
 			<input name="address" type="text" size="34" />
		  </div>

		<div class="clearfix">
 		<label>Post Code:</label>
	 		<input name="postcode" type="text" size="34" />
		  </div>

		<div class="clearfix">
 		<label>Telephone:</label>
 			<input name="tel" type="text" size="34" />
		  </div>

		<div class="clearfix">
 		<label>Your Email:</label>
 			<input name="email" type="text" size="34" />
		  </div>

		<div class="clearfix">
 		<label>How did you find us?</label>
		<SELECT NAME="find" SIZE="1">
		<OPTION SELECTED>n/a.
		<OPTION>Recommendation
		<OPTION>Leaflet
		<OPTION>Local Press
		<OPTION>Search Engine
		<OPTION>Other
		</SELECT>
		</div>

		<div class="clearfix">
			<label>Brief Enquiry:</label>
		  <textarea name="enquiry" rows="5" cols="30"></textarea>
 		</div>

		<div class="clearfix">
 		<label>Send Your Enquiry:</label>
 		<input type="submit" class="button" value="Submit this Form" />
		  </div>

	</form>
</div> 

</div>

<?php include("includes/footer.php"); ?>

 </div>
</body>
</html>

 

and here is my send mail code

 

<?php

 $name = $_REQUEST['name'];
 $address = $_REQUEST['address'];
 $postcode = $_REQUEST['postcode'];
 $tel = $_REQUEST['tel'];
 $email = $_REQUEST['email'];
 $find = $_REQUEST['find'];
 $enquiry = $_REQUEST['enquiry'];

$message = "You have been contacted through your website

Supplied information

Name: $name
Address: $address
Postcode: $postcode 
Telephone number: $tel 
Email address: $email

Found the Website Via $find 

Enquiry: 
$enquiry

click here for a map of to there location
http://www.multimap.com/map/browse.cgi?pc=$postcode
(map only works if contact supplied a postcode)";

ini_set("sendmail_from", "root@mysite.co.uk");
mail("myemail@myemail.com", "Website Enquiry", "$message", "From: Website Enquiry");

header( "Location: http://www.mysite.co.uk/thankyou.php" ); 

?>

 

thanks

<?php include("includes/top.php"); ?>

 <title>Contact Us</title>

<?php include("includes/keywords.php"); ?>
<?php include("includes/header.php"); ?>

<?php include("includes/nav.php"); ?>
<?php include("includes/colum.php"); ?>


<div id="content">

	<h2>Conact Us</h2>

	<p>Fill out the form below and we will contact you ASAP</p>

<div id="formcontainer">

	<script type="text/javascript">
		<!--

		function checkMailto(theForm) {
		if (theForm.name.value=="") {
		alert("Please enter your name");
		theForm.name.focus();
		return false;
		}
		if (theForm.tel.value=="") {
		alert("Please enter your telephone number");
		theForm.tel.focus();
		return false;
		}
		if (theForm.email.value=="") {
		alert("Please enter a valid email address");
		theForm.tel.focus();
		return false;
		}

		return true;
		}
		//-->
	</script>

	<form action="sendmail.php" name="mailForm" method="post" onSubmit=" return checkMailto(this);">


		  <div class="clearfix">
		<label>Your Name:</label>
			 <input name="name" type="text" size="34" />
		</div>

		  <div class="clearfix">
		 <label>Your Address:</label>
			 <input name="address" type="text" size="34" />
		  </div>

		<div class="clearfix">
		 <label>Post Code:</label>
			 <input name="postcode" type="text" size="34" />
		  </div>

		<div class="clearfix">
		 <label>Telephone:</label>
			 <input name="tel" type="text" size="34" />
		  </div>

		<div class="clearfix">
		 <label>Your Email:</label>
			 <input name="email" type="text" size="34" />
		  </div>

		<div class="clearfix">
		 <label>How did you find us?</label>
		<SELECT NAME="find" SIZE="1">
		<OPTION SELECTED>n/a.
		<OPTION>Recommendation
		<OPTION>Leaflet
		<OPTION>Local Press
		<OPTION>Search Engine
		<OPTION>Other
		</SELECT>
		</div>

		<div class="clearfix">

		<label>What is 2x2?</label>
		<input type="text" name="captcha" />
		</div>

		<div class="clearfix">
		<label>Brief Enquiry:</label>
		  <textarea name="enquiry" rows="5" cols="30"></textarea>
		 </div>

		<div class="clearfix">
		 <label>Send Your Enquiry:</label>
		 <input type="submit" class="button" value="Submit this Form" />
		  </div>

	</form>
</div>

</div>

<?php include("includes/footer.php"); ?>

 </div>
</body>
</html>

 

<?php

 $name = $_POST['name'];
 $address = $_POST['address'];
 $postcode = $_POST['postcode'];
 $tel = $_POST['tel'];
 $email = $_POST['email'];
 $find = $_POST['find'];
 $enquiry = $_POST['enquiry'];
 $captcha = $_POST['captcha'];

if ($captcha != 4) {
  echo "F**K OFF!";
}else {

$message = "You have been contacted through your website

Supplied information

Name: $name
Address: $address
Postcode: $postcode
Telephone number: $tel
Email address: $email

Found the Website Via $find

Enquiry:
$enquiry

click here for a map of to there location
http://www.multimap.com/map/browse.cgi?pc=$postcode
(map only works if contact supplied a postcode)";

ini_set("sendmail_from", "root@mysite.co.uk");
mail("myemail@myemail.com", "Website Enquiry", "$message", "From: Website Enquiry");

header( "Location: http://www.mysite.co.uk/thankyou.php" );

}

?>

 

Don't use $_REQUEST, use $_POST to get the data.

 

If need be you can make it a bit more complicated pretty easily, by using animal names or something like that.

 

All HTML tags should be lowercase too, those SELECT and OPTION should be select and option

  • Author

thanks for that!

 

what is the dirrerence between post and request and why use post over request???

  • Author
I got mine from White Hat Web Design, then customised it to my requirements.

 

ill try this one and see if i can get this to work. ive tried a few like this already and non works all gave php errors.

  • Author

right here is another problem i dont know. if someone was to up the code in wrong they get an error message, but how can i send the user back to the conact form and still have there information filled in?? so they just need to enter the correct security code.

 

or return to the contact form and diplay the security code in red or with a message saying incorrect code.

Change the echo "F**K OFF!";

 

To:

 

$_SESSION['errors']['captcha'] = 'Wrong captcha';
header('Location: addressoftheoriginalfile.php');

 

Then on your form you could pull out the $_SESSION['errors'] array and then run unset($_SESSION['errors']).

 

Then on the form you can look for the array from $_SESSION['errors'] then print the error next to the right element.

 

$_POST is just more secure than $_REQUEST as $_REQUEST allows both $_GET and $_POST data.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.