Store and Email the form information using php and mysql | Sanwebcorner

Store and Email the form information using php and mysql

In this post i am going to explain about how to store the form datas to the database and also send the same information to the mail id at a same time simultaneously.


This is very useful for the developers who wants to store and sent info to mail at a same time. In this post on submit the form, The form information goes the the mail and also insert the form datas to the database simultaneously.



<?php

if(isset($_POST['email'])) {
$email_to = "youremail@gmail.com";
    $email_subject = "form details";

$name = $_POST["name"];
$email = $_POST["email"];
$phone = $_POST["phone"];
$enquiry = $_POST["enquiry"];
$message = $_POST["message"];

$email_message = "Form 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($name)."\n";
    $email_message .= "Email: ".clean_string($email)."\n";
    $email_message .= "Telephone: ".clean_string($phone)."\n";
$email_message .= "Enquiry: ".clean_string($enquiry)."\n";
    $email_message .= "Message: ".clean_string($message)."\n";

$headers = 'From: '.$email."\r\n".
'Reply-To: '.$email."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);


}




if(isset($_POST["submit"])) {
$name = $_POST["name"];
$email = $_POST["email"];
$phone = $_POST["phone"];
$enquiry = $_POST["enquiry"];
$message = $_POST["message"];

$conn = mysqli_connect("localhost","root","","vijaykiran");

$sql="INSERT INTO cmnenquiry (name, email,phone,enquiry,message) VALUES ('" . $name. "', '" . $email. "','" . $phone. "','" . $enquiry. "','" . $message. "')";
$result= mysqli_query($conn,$sql);
if($result) {
$message1 = "Your contact information is saved successfully";
echo '<script>alert("Your request is received . We will contact you soon...");</script>';
    echo '<script>location.href = "index.php"</script>';
echo $message1;
}

}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Vijay Kiran Group of Educational Institutes Common Enquiry Form</title>
<link rel="stylesheet" href="bootstrap.css" />
<link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet">
</head>
<body>
<div class="header1"> <h3 style="color:#fff; text-align:center; font-size:25px;">Vijay Kiran Group of Educational Institutes Common Enquiry Form</h3></div>
<div class="container">
<div class="boot-form">
<form action="<?php htmlentities($_SERVER['PHP_SELF']);?>" method="post">
<div class="form-group">
  <label for="usr">Name:</label>
  <input type="text" class="form-control" id="usr" name="name">
</div>

    <div class="form-group">
    <label for="email">Email address:</label>
    <input type="email" class="form-control" id="email" name="email">
  </div>
  <div class="form-group">
  <label for="usr">Phone:</label>
  <input type="text" class="form-control" id="usr" name="phone">
  </div>
  <div class="form-group">
  <label for="sel1">Enquiry About:</label>
  <select class="form-control" id="sel1" name="enquiry">
    <option>International Centre For Excellence (ICE)</option>
    <option>National Centre For Excellence (NCFE)</option>
    <option>Early Foundation (EF) </option>
    <option>General</option>
  </select>
</div>
  <div class="form-group">
  <label for="comment">Message:</label>
  <textarea class="form-control" rows="5" id="comment" name="message"></textarea>
  </div>
<button type="submit" class="btn btn-primary" name="submit">Submit</button>
</form>
</div>
</div>
<footer>
<div class="container">
<p class="foot-text"> Copyright 2016 &copy; VIJAY KIRAN</p>
</div>
</footer>
</body>
</html>

Post a Comment

Labels

360 degree view product image 3d rotate 3d text 3step-form Accordion menu ajax All Browsers Animated Background Gradient animation audio controller auto complete Best accordion menu bootstrap border bounce effect on hover Breadcrumb calculate age by dob calendar Captcha change image on mouse move color chooser countdown Counter on scroll create random number Css css animation css buttons css hover css3 customized upload Button Date picker delete data from table Different scroll speed email otp verification email verifier Embed eventlist Expanding Menu feedbck form flash news section close button full screen menu Google custom search Google Maps Google reCAPTCHA Google site search gradient hide menu Horizontal News ticker Hover Htm Html html dropdown html form html5 html5 form validation Iframe image hover increment decrement textbox value based on select box Javascript Jquery js Layered image effect on mouse hover lock & unlock page scroll marquee marquee with close button mobile number validation mobile otp login Multi-level-drop-down-menu multi-level-form Multi-Step-form mysql News ticker on hover change text to image our team page password generator password strength checker Photoshop PHP populate html selectbox Popup image on click the link pure css Question type form random number generate Random password Redirect page Based on the select box while submit the form responsive responsive menu responsive popup box Responsive Vertical Time line design rotate image selectbox based on select box simple coming soon page simple countdown based on end date simple typing effect slider sliding tab sms otp login statistic counter on scroll switch tag shape team member Time picker toggle toggle view transparent button underline animation up down slide validation vertical fixed sidebar Webtips Youtube