Advertisement
Guest User

Untitled

a guest
Apr 3rd, 2017
536
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.31 KB | None | 0 0
  1. <?php
  2. function constructEmailBody () {
  3. $fields = array("name" => true, "email" => true, "address" => true, "phone" => true, "contact-time" => true);
  4. $message_body = "";
  5. foreach ($fields as $name => $required) {
  6. $postedValue = $_POST[$name];
  7. if ($required && empty($postedValue)) {
  8. errorResponse("$name is empty.");
  9. } else {
  10. $message_body .= ucfirst($name) . ": " . $postedValue . "n";
  11. }
  12. }
  13. return $message_body;
  14. }
  15.  
  16. //attempt to send email
  17. $emailBody = constructEmailBody();
  18. require './vender/php_mailer/PHPMailerAutoload.php';
  19. $email = new PHPMailer;
  20. $email->CharSet = 'UTF-8';
  21. $email->isSMTP();
  22. $email->Host = 'smtp.gmail.com';
  23. $email->SMTPAuth = true;
  24. $email->Username = 'email@domain.com';
  25. $email->Password = 'MyPassword';
  26.  
  27. $email->SMTPSecure = 'tls';
  28. $email->Port = 587;
  29.  
  30. $email->setFrom($_POST['email'], $_POST['name']);
  31. $email->addAddress('email@domain.com');
  32. $email->Subject = 'Estimate Request Answers';
  33. $email->Body = $emailBody;
  34. //try to send the message
  35. if($email->send()) {
  36. echo json_encode(array('message' => 'Thank you! Your message was successfully submitted.'));
  37. } else {
  38. errorResponse('An unexpected error occured while attempting to send the email: ' . $email->ErrorInfo);
  39. }
  40. ?>
  41.  
  42. <form role="form" id="estimateForm" method="POST">
  43. <div class="col-xs-12 contact-information">
  44. <div class="form-group">
  45. <fieldset>
  46. <legend>Contact Information</legend>
  47. <div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
  48. <label class="control-label" for="name">Name</label>
  49. <input type="text" class="form-control" id="name" name="name" placeholder="Enter Name">
  50. <label class="control-label" for="email">Email</label>
  51. <input type="email" class="form-control" id="email" name="email" placeholder="Enter Email">
  52. <label class="control-label" for="address">Address</label>
  53. <input type="text" class="form-control" id="address" name="address" placeholder="Enter Address">
  54. </div>
  55. <div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
  56. <label class="control-label" for="phone">Phone Number</label>
  57. <input type="tel" class="form-control" id="phone" name="phone" placeholder="Enter Phone Number">
  58. <label class="control-label" for="contact-time">Preferred Contact Time</label>
  59. <select class="selectpicker contact-time" id="contact-time" name="contact-time" title="Preferred Contact Time">
  60. <option value="Morning">Morning (9-11am)</option>
  61. <option value="Afternoon">Afternoon (11-2pm)</option>
  62. <option value="Evening">Evening (2-5pm)</option>
  63. </select>
  64. <label class="control-label" for="contact-method">Preferred Contact Method</label>
  65. <select class="selectpicker contact-method" id="contact-method" name="contact-method" title="Preferred Contact Method">
  66. <option>By Phone</option>
  67. <option>By Email</option>
  68. </select>
  69. </div>
  70. </fieldset>
  71. </div>
  72. </div>
  73. </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement