send email contact form detail
index.php
<?php
//index.php
$count = 0;
$error = '';
if(isset($_POST['submit']))
{
$name = '';
$phone = '';
$email = '';
$address = '';
if(empty($_POST['name']))
{
$error .= '<p class="text-danger">Name is Required</p>';
}
else
{
if(!preg_match("/^[a-zA-Z ]*$/",$_POST["name"]))
{
$error .= '<p class="text-danger">Only Alphabet allowed in Name</p>';
}
else
{
$name = $_POST['name'];
}
}
if(empty($_POST["email"]))
{
$error .= '<p class="text-danger">Email Address is Required</p>';
}
else
{
if(!filter_var($_POST["email"], FILTER_VALIDATE_EMAIL))
{
$error .= '<p class="text-danger">Invalid email format</p>';
}
else
{
$email = $_POST["email"];
}
}
if(empty($_POST["phone"]))
{
$error .= '<p class="text-danger">Phone Number is Required</p>';
}
else
{
if(!preg_match("/^[0-9]*$/",$_POST["phone"]))
{
$error .= '<p class="text-danger">Only Numbers allowed in Phone</p>';
}
else
{
$phone = $_POST["phone"];
}
}
if(empty($_POST["address"]))
{
$error .= '<p class="text-danger">Address is Required</p>';
}
else
{
$address = $_POST["address"];
}
if($error == '')
{
$count = $count + 1;
$error = '<label class="text-success">Form Data Submitted</label>';
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>How to Restore Form Data using Jquery with PHP</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="savy.js"></script>
</head>
<body>
<br />
<h2 align="center"><a href="#">How to Restore Form Data using Jquery with PHP</a></h2>
<br />
<div class="container">
<div class="row">
<div class="col-lg-6" style="margin:0 auto; float:none;">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">User Form</h3>
</div>
<div class="panel-body">
<form method="post">
<span class="text-danger"><?php echo $error; ?></span>
<div class="form-group">
<label>Name</label>
<input type="text" name="name" id="name" class="form-control" />
</div>
<div class="form-group">
<label>Email</label>
<input type="text" name="email" id="email" class="form-control" />
</div>
<div class="form-group">
<label>Phone</label>
<input type="text" name="phone" id="phone" class="form-control" />
</div>
<div class="form-group">
<label>Address</label>
<textarea name="address" id="address" class="form-control"></textarea>
</div>
<div class="form-group">
<label>Gender</label>
<select name="gender" id="gender" class="form-control">
<option value="male">Male</option>
<option value="female">Female</option>
</select>
</div>
<div class="form-group">
<label>Programming Languages</label><br />
<div class="checkbox-inline">
<label><input type="checkbox" name="languages[]" id="php_language" value="PHP">PHP</label>
</div>
<div class="checkbox-inline">
<label><input type="checkbox" name="languages[]" id="java_language" value="Java">Java</label>
</div>
<div class="checkbox-inline">
<label><input type="checkbox" name="languages[]" id="net_language" value=".Net">.Net</label>
</div>
</div>
<div class="form-group" align="center">
<input type="submit" name="submit" class="btn btn-info" value="Submit" />
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
<script>
$(document).ready(function(){
<?php
if($count == 0)
{
?>
$('#name').savy('load');
$('#email').savy('load');
$('#phone').savy('load');
$('#address').savy('load');
$('#gender').savy('load');
$('#php_language').savy('load');
$('#java_language').savy('load');
$('#net_language').savy('load');
<?php
}
else
{
?>
$('#name').savy('destroy');
$('#email').savy('destroy');
$('#phone').savy('destroy');
$('#address').savy('destroy');
$('#gender').savy('destroy');
$('.languages').savy('destroy');
$('#php_language').savy('destroy');
$('#java_language').savy('destroy');
$('#net_language').savy('destroy');
<?php
}
?>
});
</script>
mail.html
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {font-family: Arial, Helvetica, sans-serif;}
input[type=text], select, textarea {
width: 100%;
padding: 12px;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
margin-top: 6px;
margin-bottom: 16px;
resize: vertical;
}
input[type=submit] {
background-color: #4CAF50;
color: white;
padding: 12px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
}
input[type=submit]:hover {
background-color: #45a049;
}
.container {
border-radius: 5px;
background-color: #f2f2f2;
padding: 20px;
}
</style>
</head>
<body>
<h3>Contact Form</h3>
<div class="container">
<form action="www.bhagyawebtechnologies.in/sendmail.php">
<label for="fname">First Name</label>
<input type="text" id="fname" name="firstname" placeholder="Your name..">
<label for="lname">Last Name</label>
<input type="text" id="lname" name="lastname" placeholder="Your last name..">
<label for="lname">email</label>
<input type="text" id="email" name="email" placeholder="Your last name..">
<label for="lname">telephone</label>
<input type="text" id="telephone" name="telephone" placeholder="Your last name..">
<label for="country">Country</label>
<select id="country" name="country">
<option value="australia">Australia</option>
<option value="canada">Canada</option>
<option value="usa">USA</option>
</select>
<label for="comments">Subject</label>
<textarea id="comments" name="comments" placeholder="Write something.." style="height:200px"></textarea>
<input type="submit" value="Submit">
</form>
</div>
</body>
</html>
sendmail.php
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "abc@gmail.com";
$email_subject = "Meet Now";
function died($error) {
// your error code can go here
echo "but there were error found with the form you submitted. ";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['fname]) ||
!isset($_POST['lname']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['country']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$fname = $_POST['fname']; // required
$lname = $_POST['lname']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$country = $_POST['country']; // not required
$comments = $_POST['comments']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$fname)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$lname)) {
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
}
if(strlen($comments) < 0) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Meet Now details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Name: ".clean_string($fname)."\n";
$email_message .= "city: ".clean_string($lname)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Mobile: ".clean_string($telephone)."\n";
$email_message .= "Date: ".clean_string($country)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- include your own success html here -->
<!DOCTYPE html>
<html lang="en">
<head>
<title>Welcome to Shaadiclubs.com -Wedding serv</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<style>
/* Remove the navbar's default margin-bottom and rounded borders */
.navbar {
margin-bottom: 0;
border-radius: 0;
background-color: white;
text color: #EC2B2E;
}
li:hover {background: #E72E5B;}
body {
position: relative;
height: 100%;
}
#Why{padding-top:50px;height:500px;color: #fff; background-color: ;}
#Service {padding-top:50px;height:500px;color: #fff; background-color: ;}
#Vendor {padding-top:50px;height:900px;color: #fff; background-color: ;}
#Testimoinal {padding-top:50px;height:500px;color: #fff; background-color: ;}
/* Add a gray background color and some padding to the footer */
footer {
background-color: #f2f2f2;
padding:32px;
}
.carousel-inner img {
width: 100%; /* Set width to 100% */
margin: auto;
min-height:200px;
}
/* Hide the carousel text when the screen is less than 600 pixels wide */
@media (max-width: 600px) {
.carousel-caption {
display: none;
}
}
footer {
background-color: #E72E5B;
color: #f5f5f5;
padding: 20px;
}
footer a {
color: #f5f5f5;
}
footer a:hover {
color: #777;
text-decoration: none;
}
input[type=text]:focus, input[type=password]:focus {
background-color: #161515;
outline: none;
}
a {
color: #EF2D30;
}
/* Set a style for the submit button */
.btn {
background-color: #F1AE34;
color: white;
padding: 8px 10px;
border: none;
cursor: pointer;
width: 25%;
opacity: 0.9;
}
</style>
</head>
<body>
<?php include('includes/header.php');?>
</br></br></br></br></br></br></br></br></br></br></br></br></br></br></br>
<b><font size="5">
Thank you for contacting us. We will be in touch with you very soon.</b></font>
<?php
}
?>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br></br>
<?php include('includes/footer.php');?>
</body>
</html>