Simple Mail Sending Contact Form using PHP and Jquery

here am sharing simple email sending contact us form source code using php and jquery,
for this you need a PHP working environment with SMTP protocol enable
and jQuery plugin
here is the source for sending mail
HTML CODE:
[code language="html"]
<div class="content col-md-5 wow fadeInDown" data-wow-duration="1000ms" data-wow-delay="300ms">
<form id="main-contact-form" class="contact-form mail_class" name="contact-form" method="post" action="email.php">
<div class="err_msg"></div>
<div class="form-group">
<input type="text" class="form-control" name="first_name" id="Inputname" placeholder="Full Name" required="">
<label for="first_name"><i class="icon-tag"></i></label>
<div class="clearfix"></div>
</div>
<div class="form-group">
<input type="email" class="form-control" name="email" id="Inputemail1" placeholder="email@example.com" required="">
<label for="email"><i class="icon-inbox"></i></label>
<div class="clearfix"></div>
</div>
<div class="form-group">
<input type="telephone" class="form-control" name="telephone" id="Inputtelephone" placeholder="0999 666 888" required="">
<label for="telephone"><i class="icon-inbox"></i></label>
<div class="clearfix"></div>
</div>
<div class="form-group textarea">
<textarea rows="6" class="form-control" name="message" id="exampleInputMessage" placeholder="Write Message" required=""></textarea>
<label for="exampleInputMessage"><i class="icon-pencil"></i></label>
<div class="clearfix"></div>
</div>
<button type="submit" name="submit" value="submit" class="btn btn-large"> Send Message </button>
</form>
<div class="clearfix"></div>
</div>
[/code]
JQuery CODE:
[code language="javascript"]
<script type="text/javascript">
$(".mail_class").submit(function(){
var form_data=$(this).serializeArray();
$.ajax({
method:"POST",
url:"send_mail.php",
data:form_data,
beforeSend:function(){
$(".err_msg").html("Sending mail please wait..");
},
success:function(data){
if(data=="1")
$(".err_msg").html("Sending mail successfull");
else
$(".err_msg").html("Sending mail failed");
},
error:function(){
$(".err_msg").html("Sending mail failed");
}
})
});
</script>
[/code]
PHP CODE:
//send_mail.php
[code language="php"]
<?php
if($_POST){
$name=stripslashes($_POST["first_name"]);
$from=stripslashes($_POST["email"]);
$mobile=stripslashes($_POST["telephone"]);
$message=stripslashes($_POST["message"]);

$email_message .= "First Name: ".$name."\n";
$email_message .= "Email: ".$from."\n";
$email_message .= "Telephone: ".$mobile."\n";
$email_message .= "Message: ".$message."\n";

$email_to="rajeshpatnaik06@gmail.com";
$email_subject="Contact Form Alert";

$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
if(@mail($email_to, $email_subject, $email_message, $headers)){
echo "1";
}else{
echo "0";
}
}
}
?>
[/code]

that's it. Feel free to comment here
keep visiting...:)

Comments

Post a Comment

Popular posts from this blog

Codeigniter with Admin LTE

onclick anchor tag open url in bootstrap model