Ajax contact form with recaptcha

Download recaptcha library from here
There are four step need to complete and they are:
Step 1: create index.php with this code
Step 2: create contact.js
Step 3: create captcha_validation.php
Step 4: create mail.php

Step 1: create index.php with this code

<script src="//code.jquery.com/jquery-1.8.1.min.js"></script>
<script src="//jqueryvalidation.org/files/dist/jquery.validate.min.js"></script>
<script src="contact.js"></script>

<script type="text/javascript">
    var RecaptchaOptions = {
        theme : 'clean'
    };
</script>
<?php

include('recaptchalib.php');
$publickey = "6LewXewSAAAAANSyq3pKWEME8Yjeg2g6avlHdthN";
$privatekey = "6LewXewSAAAAAC70yiCqkyHoKHvxBrjUSXoATFNZ";

# the response from reCAPTCHA
$resp = null;
# the error code from reCAPTCHA, if any
$error = null;

?>
<div class="contact-form-wrapper">
    <h3>Contact us</h3>
    <form action="" method="post" class="contact_form" id="contact_form_ajax">
        <table  class="contact-us"  id="quote-request-form" border="0" cellspacing="0" cellpadding="0">
            <tr>
                <td valign="top" class="label">Name  <span class="required">*</span></td>
                <td valign="top" class="field">
                    <input type="text" name="your_name" value=""/>
                </td>
            </tr>
            <tr>
                <td valign="top"  class="label">Email <span class="required">*</span></td>
                <td valign="top" class="field">
                    <input type="email" name="email" value=""/>
                </td>
            </tr>
            <tr>
                <td valign="top"  class="label">Phone</td>
                <td valign="top" class="field">
                    <input type="text" name="phone" value="" />
                </td>
            </tr>
            <tr>
                <td valign="top"  class="label">Message <span class="required">*</span></td>
                <td valign="top" class="field">
                    <textarea name="message"></textarea>
                </td>
            </tr>
            <tr>
                <td colspan="2" valign="top">
                    <div class="main_captcha"><?php echo recaptcha_get_html($publickey, $error); ?> </div>
                    <div class="captchaStatus"></div>
                </td>
            </tr>
            <tr>
                <td colspan="2" valign="top">
                    <input type="submit" value="Send" />
                </td>
            </tr>
        </table>
    </form>
    <div class="contact_form_msg"></div>
</div>


Step 2: create contact.js

jQuery(document).ready(function(){

    jQuery("#contact_form_ajax").validate({
        rules: {
            your_name: "required",
            email: {
                required: true,
                email: true
            },
            message:'required'
        },
        messages: {
           /* your_name: "Please enter your name",
            email: "Please enter a valid email address"*/
        },
        submitHandler: function(form) {

            jQuery('.contact_form_msg').html('');
            challengeField = jQuery(form).find("input#recaptcha_challenge_field").val();
            responseField = jQuery(form).find("input#recaptcha_response_field").val();

            var html = jQuery.ajax({
                type: "POST",
                url: 'captcha_validation.php',
                data: "recaptcha_challenge_field=" + challengeField + "&recaptcha_response_field=" + responseField,
                async: false
            }).responseText;

            if(html != "success") {
                jQuery(form).find(".captchaStatus").html("The security code you entered did not match.");
                Recaptcha.reload();
                return false;
            } else {

                jQuery.ajax({
                    type:'POST',
                    url:'mail.php',
                    data:jQuery(form).serialize(),
                    success:function(response){
                        //jQuery(form).resetForm();
                        jQuery("#contact_form_ajax").validate().resetForm();
                        if (response==1) {
                            jQuery('.contact_form_msg').html('<div class="success">Your message was sent successfully</div>');
                        }else{
                            jQuery('.contact_form_msg').html('<div class="error">Please try again</div>');
                        }
                    }
                });
                jQuery(form).find(".captchaStatus").html("");
                Recaptcha.reload();
            }
            return false;
        }
    });
});

Step 3: create captcha_validation.php

<?php
include('recaptchalib.php');
$privatekey = "6LewXewSAAAAAC70yiCqkyHoKHvxBrjUSXoATFNZ";

$resp = recaptcha_check_answer($privatekey,
    $_SERVER["REMOTE_ADDR"],
    $_POST["recaptcha_challenge_field"],
    $_POST["recaptcha_response_field"]);
if ($resp->is_valid) {
    echo "success";
} else {
    die("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
        "(reCAPTCHA said: " . $resp->error . ")");
}

Step 4: create mail.php

<?php
if(isset($_POST)&&sizeof($_POST)>0){

    $email = $_POST['email'];
    $message ='<html>';
    $message .='<body>';
    $message .='<table>';
    $message .='<tr><td valign="top">Name</td><td>'.$_POST['your_name'].'</td></tr>';
    $message .='<tr><td valign="top">Email</td><td>'.$_POST['email'].'</td></tr>';
    $message .='<tr><td valign="top">Phone</td><td>'.$_POST['phone'].'</td></tr>';
    $message .='<tr><td valign="top">Message</td><td>'.stripslashes($_POST['message']).'</td></tr>';
    $message .='</table>';

    $message .= "<p>This mail is sent via contact form of the site <a href='http://webalive.com.au/'>http://webalive.com.au/</a></p>";
    $message .='</body>';
    $message .='</html>';

    $to = 'autobillsmtp@webalive.biz';
    $bcc = '';

    $subject = 'Contact us query';
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    $headers .= 'From: webalive.com.au <'.$email.'>'."\r\n" .
        'Bcc:'.$bcc. "\r\n" .
        'Reply-To: '.$email . "\r\n" .
        'X-Mailer: PHP/' . phpversion();

    if(mail($to, $subject, $message, $headers)){
        echo 1;
    }else{
        echo 0;
    }
}