How to use contact form core php with jquery ajax

HTML Form

<!–
.isrequired.error{border-color:red;}
.alert{background:#f3f3f3 none repeat scroll 0 0;border:1px solid;border-radius:3px;margin-bottom:10px;padding:10px;}
.alert{display:none;}
.alert.alert-danger{color:red;}
.alert.alert-success{color:green;}

–>

File: frontend-ajax.js

jQuery(document).ready(function() {

jQuery(“.submit_contact_btn”).click(function() {

//on focus
jQuery(“#contact_form .isrequired, #contact_form .isrequired”).focus(function(){
jQuery(this).removeClass(‘error’);
});

//on blur
jQuery(“#contact_form .isrequired, #contact_form .isrequired”).blur(function()
{
if(jQuery(this).val().trim() == ”)
{
jQuery(this).addClass(‘error’);
} else {
jQuery(this).removeClass(‘error’);
}
});

if(jQuery(“#firstname”).val().trim() == ” || jQuery(“#lastname”).val().trim() == ” || jQuery(“#phonenumber”).val().trim() == ” || jQuery(“#email”).val().trim() == ” || jQuery(“#message”).val().trim() == ” )
{

jQuery(“#notic_contact.alert”).show();
jQuery(“#notic_contact.alert”).addClass(“alert-danger”);
jQuery(“#notic_contact.alert”).html(“Please fill all mandatory fields”);

jQuery(“#contact_form .isrequired” ).each(function() {
filedValue = jQuery(this).val().trim();
if(filedValue == ”)
{
jQuery(this).addClass(‘error’);
} else {
jQuery(this).removeClass(‘error’);
}
});
jQuery(“#phonenumber”).on(“keypress”,function (event) {
jQuery(this).val($(this).val().replace(/[^\d].+/, “”));
if ((event.which 57)) {
event.preventDefault();
}
jQuery(this).addClass(‘error’);
});

} else if (!ValidateEmail(jQuery(“#email”).val())) {

jQuery(“#notic_contact.alert”).show();
jQuery(“#notic_contact.alert”).addClass(“alert-danger”);
jQuery(“#notic_contact.alert”).html(“Please enter valid email address”);
jQuery(“#email”).addClass(‘error’);

} else {

jQuery(“#buy_book_form_loding”).show();
var formData = jQuery(“#contact_form”).serialize();

jQuery.ajax({
type:”POST”,
url: “contact_mail.php”,
data: formData,

success:function(data) {
//console.log(data);
jQuery(“#buy_book_form_loding”).hide();
jQuery(“#contact_form”)[0].reset();

jQuery(“#notic_contact.alert”).show();
jQuery(“#notic_contact.alert”).addClass(“alert-success”);
jQuery(“#notic_contact.alert”).html(“Thank You! Your message has been sent.”);
},
error: function(errorThrown){
console.log(errorThrown);
}
});
}
});
});

function ValidateEmail(email) {
var expr = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
return expr.test(email);
};

contact_mail.php

<?php

$mail_to = “urmil.bca5880@gmail.com”;
# Sender Data
$subject = “Contact form – Argotime”;
$firstname = $_POST[“firstname”];
$lastname = $_POST[“lastname”];
$phonenumber = $_POST[“phonenumber”];
$email = $_POST[“email”];
$message = $_POST[“message”];

# Mail Content
$content .= “First Name: $firstname\n”;
$content .= “Last Name: $lastname\n”;
$content .= “Phone Number: $phonenumber\n”;
$content .= “Email: $email\n”;
$content .= “Message:$message\n”;

# email headers.
$headers = “From: $firstname “;

# Send the email.
$success = mail($mail_to, $subject, $content, $headers);

if($success){
$msg = “Thank You! Your message has been sent.”;
$status = true;
}
else{
$status = false;
$msg = “Oops! Something went wrong, we couldn’t send your message.”;
}

############################# send email end ############################
$response_array = array( ‘status’ => $status, ‘message’ => $msg);
echo json_encode($response_array);

die();
?>