Friday, August 26, 2011

Newsletter Script with Simple Captcha using PHP

In previous Post We seen how to create a Simple capcha. Now we look how to integrate that simple Captcha with HTML Form. Now I am going to show you a Newsletter Subscriber with our Simple Captcha.

Kindly view  How to Create a Simple Captcha in PHP before the Newsletter Integration of this Capcha

Let me create a HTML form look like this
 


<?php
session_start();

if(isset($_POST['subscribe']))
{
	$email=$_POST['email'];
	if(!preg_match('/([\w-\.]+)@((?:[\w]+\.)+)([a-zA-Z]{2,4})/',$email))
	{
		$response="Invalid Email Address";
	}elseif(strcmp($_SESSION['capcha_code'],$_POST['code'])!=0)
	{
		$response="Invalid Verfification Code";
	}else
	{
		//Save Email address
		$response="Subscribed! Thank you !";
	}
	
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Simple Capcha : Example Form</title>
<style type="text/css">
<!--
body,td,th {
	font-family: Verdana, Geneva, sans-serif;
	font-size: 11px;
	color: #333;
}
body {
	margin-left: 10px;
	margin-top: 10px;
}
-->
</style></head>

<body>
<form action="" method="post" name="subscribe">

<table border="0" cellspacing="0" cellpadding="5" style="border:1px solid #CCC;">
  <tr>
    <td colspan="2" bgcolor="#D6D6D6"><b>Subscribe Newsletter</b></td>

    </tr>
  <tr>
    <td>Email Address</td>
    <td><input name="email" type="text" id="email"></td>

  </tr>
  <tr>
    <td>Antibot</td>
    <td><input type="text" name="code" id="code" value="Enter code here" onFocus="this.value=''"></td>

  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>
    
    <img src="capcha_image.php" alt="Verify" width="75" height="25" style="border:2px solid #000;"></td>

  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><input name="subscribe" type="submit" id="subscribe" value="Subscribe"></td>

  </tr>
  <tr>
    <td colspan="2">
    <?php echo @$response; ?>
    </td>
    </tr>

</table>
</form>
</body>
</html> 

 
Download This Script        View Demo Download Script

1 comment: