This code is used for the basic php code of contact us form to submit the values to company mail.
HTML:
<div class="col-md-4 col-sm-4 col-xs-12" style="padding: 20px 60px;"><form enctype="multipart/form-data" id="frmemail" name="frmemail">
<fieldset class="margin-b">
<h2>Contact US :</h2>
<div class="form-group name">
<label for="form_name">Name*</label>
<input type="text" class="form-control" name="form_name" id="form_name" type="text" value="" required autofocus >
</div>
<div class="form-group name">
<label for="form_phone">Phone No*</label>
<input type="number" class="form-control" name="form_phone" id="form_phone" type="text" value="" required autofocus >
</div>
<div class="form-group name">
<label for="form_email">Email*</label>
<input type="email" class="form-control" name="form_email" id="form_email" value="" required autofocus >
</div>
<div class="form-group name">
<label for="form_subject">Subject</label>
<input type="text" class="form-control" name="form_subject" id="form_subject" value="">
</div>
<div class="form-group name">
<label for="form_message">Message</label>
<textarea name="form_message" class="form-control" id="form_message" rows="5"></textarea>
</div>
<!--
<label for="form_name">Name:<input name="form_name" id="form_name" type="text" value="" required autofocus ></label>
<label for="form_email">Email:<input type="email" name="form_email" id="form_email" value=""></label>
<label for="form_msg">Message:<textarea name="form_msg" id="form_message" rows="5"></textarea></label>
-->
</fieldset>
<input type="submit" class="form-control" name="submit" id="submit" value="Submit">
</form>
</div>
JS:
add this code in Html of contact-Us form.
$("#frmemail").submit(function(event){
event.preventDefault();
$.ajax({
type: "POST",
url: "form_process.php",
data: $("#frmemail").serialize(),
success: function(){
$('.success').fadeIn(1000);
alert("submitted successfully!!");
document.frmemail.reset();
}
});
});
</script>
PHP:
<?php
if($_POST){
$name = $_POST['form_name'];
$email = $_POST['form_email'];
$subject = $_POST['form_subject'];
$phone= $_POST['form_phone'];
$message= $_POST['form_message'];
$header = "From:".$email."\r\n";
$header.= "MIME-Version: 1.0\r\n";
$header.= "Content-Type: text/plain; charset=utf-8\r\n";
$header.= "X-Priority: 1\r\n";
$mail = "\n\nName: ".$name."\n\nEmail: ".$email."\n\nPhone: ".$phone."\n\nMeassage: ".$message."\n\n This query submitted from : http://globusitindia.com";
//send email
mail("info@xyz.com", " ".$subject, $mail, $header);
}
?>
No comments:
Post a Comment