SHARE
TWEET

Untitled

a guest Feb 4th, 2016 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <div class="col-sm-12">
  2.   <form id="SubmissionForm" action="insert.php" method="POST" role="form">
  3.     <div class="form-group">
  4.       <label for="FirstName">First Name *</label>
  5.       <input type="text" class="form-control" id="FirstName" placeholder="" name="first_name" value="" data-error="Please enter a valid first name." required maxlength="255">
  6.       <div class="help-block with-errors"></div>
  7.     </div>
  8.  
  9.     <div class="form-group">
  10.       <label for="LastName">Last Name *</label>
  11.       <input type="text" class="form-control" id="LastName" placeholder="" name="last_name" value=""  data-error="Please enter a valid last name." required maxlength="255">
  12.       <div class="help-block with-errors"></div>              
  13.     </div>
  14.  
  15.     <div class="form-group">
  16.       <label for="Email">Email address *</label>
  17.       <input type="email" class="form-control" id="Email" placeholder="" name="email" value="" data-error="Please enter a valid email address." required maxlength="255">
  18.       <div class="help-block with-errors"></div>              
  19.     </div>
  20.  
  21.     <div class="form-group">
  22.       <label for="Age">Age *</label>
  23.       <input type="text" class="form-control" id="Age" placeholder="" name="age" value="" data-error="Please enter a valid age." required maxlength="255">
  24.       <div class="help-block with-errors"></div>
  25.     </div>
  26.  
  27.     <div class="form-group">
  28.       <label for="Phone">Phone *</label>
  29.       <input type="text" class="form-control" id="Phone" placeholder="" name="phone" value="" data-error="Please enter a valid phone number." required maxlength="255">
  30.       <div class="help-block with-errors"></div>
  31.     </div>
  32.  
  33.     <div class="form-group">
  34.       <label for="StreetAddress">Street Address *</label>
  35.       <input type="text" class="form-control" id="StreetAddress" placeholder="" name="street_address" value="" data-error="Please enter a valid street address." required maxlength="255">
  36.       <div class="help-block with-errors"></div>
  37.     </div>
  38.  
  39.     <div class="form-group">
  40.       <label for="Suburb">Suburb</label>
  41.       <input type="text" class="form-control" id="Suburb" placeholder="" name="suburb" value="" maxlength="255">
  42.       <div class="help-block with-errors"></div>
  43.     </div>
  44.  
  45.     <div class="form-group">
  46.       <label for="City">City *</label>
  47.       <input type="text" class="form-control" id="City" placeholder="" name="city" value="" data-error="Please enter a valid city." required maxlength="255">
  48.       <div class="help-block with-errors"></div>
  49.     </div>
  50.  
  51.     <div class="form-group">
  52.       <label for="Postcode">Postcode *</label>
  53.       <input type="text" class="form-control" id="Postcode" placeholder="" name="postcode" value="" data-error="Please enter a valid postcode." required maxlength="255">
  54.       <div class="help-block with-errors"></div>
  55.     </div>
  56.  
  57.     <div class="form-group">
  58.       <label for="Country">Country *</label>
  59.       <input type="text" class="form-control" id="Country" placeholder="" name="country" value="" data-error="Please enter a valid country." required maxlength="255">
  60.       <div class="help-block with-errors"></div>
  61.     </div>
  62.  
  63.     <div class="form-group">
  64.       <label for="FindUs">Where did you hear about us?</label>
  65.       <input type="text" class="form-control" id="FindUs" placeholder="" name="findus" value="" maxlength="255">
  66.     </div>
  67.  
  68.     <div class="form-group">
  69.       <div class="gender-label">Gender *</div>
  70.       <div id="Gender">
  71.         <div class="radio" style="margin-top:0px;">
  72.           <label>
  73.             <input type="radio" name="gender" id="Female" value="F" required>
  74.             Female
  75.           </label>
  76.         </div>
  77.         <div class="radio">
  78.           <label>
  79.             <input type="radio" name="gender" id="Male" value="M" required>
  80.             Male
  81.           </label>
  82.         </div>
  83.       </div>
  84.       <div class="help-block with-errors"></div>
  85.     </div>
  86.  
  87.     <hr>
  88.  
  89.     <div class="form-group">
  90.       <button type="submit" class="btn btn-primary">SUBMIT</button>
  91.     </div>
  92.   </form>
  93. </div>
  94.    
  95. <?php
  96. //include 'connect.php';
  97. $servername = "servername";
  98. $username = "username";
  99. $password = "password";
  100. $dbname = "dbname";
  101.  
  102. $conn = new mysqli($servername, $username, $password, $dbname);
  103.  
  104. if ($conn->connect_error) {
  105.     die("Connection failed: " . $conn->connect_error);
  106. }
  107.  
  108. if($_SERVER['REQUEST_METHOD'] == 'POST'){
  109.     $host_email = 'email@email.com';
  110.     $host_name = 'name';
  111.  
  112.     $first_name = $_POST["first_name"];
  113.     $last_name = $_POST["last_name"];
  114.     $email = $_POST["email"];
  115.     $gender = $_POST["gender"];
  116.     $age = $_POST["age"];
  117.  
  118.     $phone = $_POST["phone"];
  119.     $findus = $_POST["findus"];
  120.     $street_address = $_POST["street_address"];
  121.  
  122.     $suburb = '';
  123.     if(isset($_POST["suburb"]) == ''){
  124.         $suburb = 'n/a';
  125.     }else{
  126.         $suburb = $_POST["suburb"];
  127.     }
  128.  
  129.     $postcode = $_POST["postcode"];
  130.     $city = $_POST["city"];
  131.     $country = $_POST["country"];
  132.  
  133.     $agree = '';
  134.     if(isset($_POST["agree"]) == ''){
  135.         $agree = 'No';
  136.     }else{
  137.         $agree = 'Yes';
  138.     }
  139.  
  140.     $sql = "INSERT INTO `dbname`.`tablename` (`first_name`, `last_name`, `email`, `gender`, `age`, `phone`, `findus`, `street_address`, `suburb`, `city`, `country`, `postcode`, `email_subscribe`, `date`)
  141.     VALUES ('$first_name', '$last_name', '$email', '$gender', '$age', '$phone', '$findus', '$street_address', '$suburb', '$city', '$country', '$postcode', '$agree', NOW());";
  142.  
  143.     if($conn->query($sql) === TRUE) {
  144.         $unique_id = $conn->insert_id;  //get the id from the last db insert
  145.  
  146.         $name = $first_name . ' ' . $last_name;
  147.  
  148.         $phone = $phone;
  149.  
  150.         require 'PHPMailerAutoload.php';
  151.  
  152.         $mail = new PHPMailer;
  153.  
  154.         //$mail->SMTPDebug = 3;                                         // Enable verbose debug output
  155.  
  156.         $mail->isSMTP();                                                // Set mailer to use SMTP
  157.         $mail->Host = 'host';                                           // Specify main and backup SMTP servers
  158.         $mail->SMTPAuth = true;                                         // Enable SMTP authentication
  159.         $mail->Username = 'username';                                   // SMTP username
  160.         $mail->Password = 'password';                                   // SMTP password
  161.         $mail->SMTPSecure = 'tls';                                      // Enable TLS encryption, `ssl` also accepted
  162.         $mail->Port = 587;                                              // TCP port to connect to
  163.  
  164.         $mail->setFrom('email@email.com', 'email');
  165.         $mail->addAddress($host_email, $host_name);                     // Add a recipient - name is optional      
  166.         $mail->addAddress($email, $first_name.' '.$last_name);          // Add a recipient - name is optional
  167.         $mail->addReplyTo('email@email.com', 'email');
  168.  
  169.         $mail->addAttachment('map.pdf');                                // Add attachments
  170.         $mail->isHTML(true);                                            // Set email format to HTML
  171.  
  172.         $mail->Subject = 'Registration ID: #'.$unique_id;
  173.  
  174.         $message = '<p><span>Name:</span><span><strong>'.$name.'</strong></span></p>
  175.         <p><span>Email:</span><span><strong>'.$email.'</strong></span></p>
  176.         <p><span>Age:</span><span><strong>'.$age.'</strong></span></p>
  177.         <p><span>Gender:</span><span><strong>'.$gender.'</strong></span></p>
  178.         <p><span>Phone Number:</span><span><strong>'.$phone.'</strong></span></p>
  179.         <p><span>Street Address:</span><span><strong>'.$street_address.'</strong></span></p>
  180.         <p><span>Suburb:</span><span><strong>'.$suburb.'</strong></span></p>
  181.         <p><span>City:</span><span><strong>'.$city.'</strong></span></p>
  182.         <p><span>Country:</span><span><strong>'.$country.'</strong></span></p>
  183.         <p><span>How did you find out about us?:</span><span><strong>'.$findus.'</strong></span></p>
  184.         <p><span>Agree to email?:</span><span><strong>'.$agree.'</strong></span></p>
  185.         <hr>';
  186.  
  187.         $email_copy = "<p>Thank you for registering.</p><p><strong>Your Registration Number is #".$unique_id."</strong></p>";
  188.  
  189.         $mail->Body = $message.$email_copy;
  190.  
  191.         $mail->AltBody = $message.'<br><p><span>Name:</span><span><strong>'.$name.'</strong></span></p><p><span>Age:</span><span><strong>'.$age.'</strong></span></p><p><span>Email:</span><span><strong>'.$email.'</strong></span></p><p><span>Gender:</span><span><strong>'.$gender.'</strong></span></p>';
  192.  
  193.         if(!$mail->send()) {
  194.             header("Location:error.php");   //if mail fails
  195.         }
  196.         else{
  197.             header("Location:thankyou.php");
  198.         }
  199.     }else{
  200.         echo("Error description: " . mysqli_error($conn)); //if db insert fails
  201.     }
  202. }
  203. $conn->close();
  204. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top