<?php
/*
* Author: Oziam Web Development
* Email: hide@address.com
*
* Call captcha code, add this to your form page
*
<img src="captcha/captcha_class.php" id="docaptcha" onclick="this.src='captcha/captcha_class.php?'+Math.random();" style="cursor:hand" title="Click to refresh code">
*
* If you want to change the default font settings like image, font, size, skew, number of characters, colour etc, edit captcha_class.php in captcha folder
*
*
*
*/
session_start();
print <<<HTML
<html>
<head>
<title>Oziam Captcha Example</title>
</head>
<body>
HTML;
$msg = '* Mandatory fields';
$name = null;
$email = null;
$text = null;
// Check submitted form for errors and proceed with mailing
if(isset($_POST['act']) && $_POST['act'] == 'send'){
$error = null;
$name = strip_tags(trim($_POST['name']));
$email = trim($_POST['email']);
$code = trim($_POST['code']);
$text = strip_tags(trim($_POST['message']));
if(empty($name)){
$error .= '<font style="line-height:1.5; color:#FF0000">Enter your name.</font><br />';
}
if(!preg_match('/^[^@\s]+@([-a-z0-9]+\.)+[a-z]{2,}$/i', $email)) {
$error .= '<font style="line-height:1.5; color:#FF0000">Enter a valid email address.</font><br />';
$email = null;
}
if($_SESSION['code'] != $code || empty($_SESSION['code'])){
$error .= '<font style="line-height:1.5; color:#FF0000">Enter correct security code <small>(case sensitive)</small>.</font><br />';
}
if(empty($text)){
$error .= '<font style="line-height:1.5; color:#FF0000">Enter a message.</font><br />';
}
if($error != null){
$msg = '<p>Incomplete information, please correct the following;<p>'.$error;
}
else{
// put your mail header and mailto command here //
// lets send the user a thankyou message then clear all the form fields and kill session code.
$msg = '<p><b>Thank you</b><p>If you require an answer someone will get back to you as soon as possible.<p>';
$name = null;
$email = null;
$text = null;
unset($_SESSION['code']);
unset($_POST);
}
}
print <<<HTML
<table align="center" style="padding-left:20px" cellpadding="10" border="0" width="100%">
<tr>
<td width="100%"><h1>Contact Us</h1><hr>
<p style="margin-top:20px">
<table border="0" cellspacing="0" width="450">
<tr align="left"><td>$msg</td></tr>
</table>
<form action="$_SERVER[PHP_SELF]" method="post">
<input type="hidden" name="act" value="send">
<table border="0" style="background:#EEEEEE" cellspacing="5" width="450">
<tr><td height="40">* Name:</td><td>
<input type="text" size="20" name="name" value="$name" maxlength="20"></td></tr>
<tr><td height="40">* Email:</td><td>
<input type="text" size="40" name="email" value="$email" maxlength="40"></td></tr>
<tr><td> </td><td><img src="captcha/captcha_class.php" id="docaptcha" onclick="this.src='captcha/captcha_class.php?'+Math.random();" align="right" style="margin-right:18px; cursor:hand" title="Click to refresh code">Enter security code:<p style="margin-top:5px">
<input type="text" size="18" name="code" maxlength="10"></td></tr>
<tr><td> </td><td><small> NB: Security code is case sensitive, click code to refresh.</small></td></tr>
<tr><td valign="top">* Message:</td><td><textarea name="message" style="width:340; height:100">$text</textarea></td></tr>
<tr><td colspan="2" align="right"><input type="submit" value="Send"> </td></tr>
</table>
</form>
</body>
</html>
HTML;
?>