Location: PHPKode > scripts > Quick Contact > quickcontact/contact.php
<?php 
$your_email ='hide@address.com';// <<=== update to your email address

session_start();
$errors = '';
$name = '';
$visitor_email = '';
$user_message = '';

if(isset($_POST['submit']))
{
	
	$name = $_POST['name'];
	$visitor_email = $_POST['email'];
	$user_message = $_POST['message'];
	///------------Do Validations-------------
	if(empty($name)||empty($visitor_email))
	{
		$errors .= "\n Name and Email are required fields. ";	
	}
	if(IsInjected($visitor_email))
	{
		$errors .= "\n Bad email value!";
	}
	if(empty($_SESSION['6_letters_code'] ) ||
	  strcasecmp($_SESSION['6_letters_code'], $_POST['6_letters_code']) != 0)
	{
	//Note: the captcha code is compared case insensitively.
	//if you want case sensitive match, update the check above to
	// strcmp()
		$errors .= "\n The captcha code does not match!";
	}
	
	if(empty($errors))
	{
		//send the email
		$to = $your_email;
		$subject="New form submission";
		$from = $your_email;
		$ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';
		
		$body = "A user  $name submitted the contact form:\n".
		"Name: $name\n".
		"Email: $visitor_email \n".
		"Message: \n ".
		"$user_message\n".
		"IP: $ip\n";	
		
		$headers = "From: $from \r\n";
		$headers .= "Reply-To: $visitor_email \r\n";
		
		mail($to, $subject, $body,$headers);
		
		header('Location: contact.php?id=sent'); // this tells the script to display the thank you message with the ?id=sent on the same page just change contact.php to your file name.
		
		// header('Location: thankyou.html'); // this code is if you have a thank you page you would like the script to redirect to.
	}
}

// Function to validate against any email injection attempts
function IsInjected($str)
{
  $injections = array('(\n+)',
              '(\r+)',
              '(\t+)',
              '(%0A+)',
              '(%0D+)',
              '(%08+)',
              '(%09+)'
              );
  $inject = join('|', $injections);
  $inject = "/$inject/i";
  if(preg_match($inject,$str))
    {
    return true;
  }
  else
    {
    return false;
  }
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html>
<head>
	<title>Contact Us</title>
<!-- define some style elements-->
<style>
.err
{
	font-family : Verdana, Helvetica, sans-serif;
	font-size : 12px;
	color: red;
}
label
{
	font-family : Arial, Helvetica, sans-serif;
	font-size : 12px; 
}
textarea#styled {
        width: 600px;
        height: 120px;
        border: 3px solid #cccccc;
        font-family:Arial, Helvetica, sans-serif;
	    font-size:17px; color:#bfbfbf; font-weight:bold;
	    border:#cbcbcb solid 1px;
	    background:#ffffff
}
.rgtWrap input.txt							{width:176px;  height:30px;  font-family:Arial, Helvetica, sans-serif; font-size:17px; color:#bfbfbf; font-weight:bold; border:#cbcbcb solid 1px; background:#ffffff}

.rgtWrap input.btn							{width:113px; height:42px; margin-top:18px; float:right; font-family:Arial, Helvetica, sans-serif; font-size:17px; color:#ffffff; font-weight:bold; text-align:center; cursor:pointer; border:0; background:url(./images/submitBtn.png) no-repeat}
.rgtWrap input.btn:active					{background-position:1px 1px}
.rgtWrap									{width:600px; float:center}
.rgtWrap h3									{width:100%}
</style>	
<!-- a helper script for vaidating the form-->
<script language="JavaScript" src="scripts/gen_validatorv31.js" type="text/javascript"></script>	
</head>

<body>
  <div class="rgtWrap">
        <h3><span>Quick</span> Contact</h3>
        <?php
if(!empty($errors)){
echo "<p class='err'>".nl2br($errors)."</p>";
}

// this code below displays a thank you message above the form saying it has been sent 
// if you chose to keep the yourfile.php?id=sent
if($HTTP_GET_VARS['id']=="sent"){
echo '<p class="err"> Thank You! Your Message Has Been Successfully sent!<br> </p>'; 
}  
?>
        
<div id='contact_form_errorloc' class='err'></div>
        <form method="POST" name="contact_form"
action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>">
 
<p>
  <label for="name">Name: </label>
  <input type="text" name="name"
value="<?php echo htmlentities($name) ?>" class="txt"> &nbsp;
  <label for="email">Email: </label>
  <input type="text" name="email"
value="<?php echo htmlentities($visitor_email) ?>" class="txt">
</p>
<p>&nbsp;</p>
<p>
  <label for="message">Message:</label>
  <br />
</p>
<center>
<textarea name="message" id="styled"  rows=8 cols=50
><?php echo htmlentities($user_message) ?></textarea>

<br />
<img src="captcha_code_file.php?rand=<?php echo rand(); ?>"
id="captchaimg" ><br />
<label for="message">Enter the code above here :</label>
<br />
<input id="6_letters_code" name="6_letters_code" type="text" class="txt">
  </center>
<input type="submit" value="Submit" name="submit" class="btn">
</form>
<script language="JavaScript">
// Code for validating the form
// Visit http://www.javascript-coder.com/html-form/javascript-form-validation.phtml
// for details
var frmvalidator  = new Validator("contact_form");
//remove the following two lines if you like error message box popups
frmvalidator.EnableOnPageErrorDisplaySingleBox();
frmvalidator.EnableMsgsTogether();

frmvalidator.addValidation("name","req","Please provide your name"); 
frmvalidator.addValidation("email","req","Please provide your email"); 
frmvalidator.addValidation("email","email","Please enter a valid email address"); 
</script>
<script language='JavaScript' type='text/javascript'>
function refreshCaptcha()
{
	var img = document.images['captchaimg'];
	img.src = img.src.substring(0,img.src.lastIndexOf("?"))+"?rand="+Math.random()*1000;
}
</script>
    </div>
<script language="JavaScript">
// Code for validating the form
// Visit http://www.javascript-coder.com/html-form/javascript-form-validation.phtml
// for details
var frmvalidator  = new Validator("contact_form");
//remove the following two lines if you like error message box popups
frmvalidator.EnableOnPageErrorDisplaySingleBox();
frmvalidator.EnableMsgsTogether();

frmvalidator.addValidation("name","req","Please provide your name"); 
frmvalidator.addValidation("email","req","Please provide your email"); 
frmvalidator.addValidation("email","email","Please enter a valid email address"); 
</script>
<script language='JavaScript' type='text/javascript'>
function refreshCaptcha()
{
	var img = document.images['captchaimg'];
	img.src = img.src.substring(0,img.src.lastIndexOf("?"))+"?rand="+Math.random()*1000;
}
</script>
</body>
</html>
Return current item: Quick Contact