Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function constructEmailBody () {
- $fields = array("name" => true, "email" => true, "address" => true, "phone" => true, "contact-time" => true);
- $message_body = "";
- foreach ($fields as $name => $required) {
- $postedValue = $_POST[$name];
- if ($required && empty($postedValue)) {
- errorResponse("$name is empty.");
- } else {
- $message_body .= ucfirst($name) . ": " . $postedValue . "n";
- }
- }
- return $message_body;
- }
- //attempt to send email
- $emailBody = constructEmailBody();
- require './vender/php_mailer/PHPMailerAutoload.php';
- $email = new PHPMailer;
- $email->CharSet = 'UTF-8';
- $email->isSMTP();
- $email->Host = 'smtp.gmail.com';
- $email->SMTPAuth = true;
- $email->Username = 'email@domain.com';
- $email->Password = 'MyPassword';
- $email->SMTPSecure = 'tls';
- $email->Port = 587;
- $email->setFrom($_POST['email'], $_POST['name']);
- $email->addAddress('email@domain.com');
- $email->Subject = 'Estimate Request Answers';
- $email->Body = $emailBody;
- //try to send the message
- if($email->send()) {
- echo json_encode(array('message' => 'Thank you! Your message was successfully submitted.'));
- } else {
- errorResponse('An unexpected error occured while attempting to send the email: ' . $email->ErrorInfo);
- }
- ?>
- <form role="form" id="estimateForm" method="POST">
- <div class="col-xs-12 contact-information">
- <div class="form-group">
- <fieldset>
- <legend>Contact Information</legend>
- <div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
- <label class="control-label" for="name">Name</label>
- <input type="text" class="form-control" id="name" name="name" placeholder="Enter Name">
- <label class="control-label" for="email">Email</label>
- <input type="email" class="form-control" id="email" name="email" placeholder="Enter Email">
- <label class="control-label" for="address">Address</label>
- <input type="text" class="form-control" id="address" name="address" placeholder="Enter Address">
- </div>
- <div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
- <label class="control-label" for="phone">Phone Number</label>
- <input type="tel" class="form-control" id="phone" name="phone" placeholder="Enter Phone Number">
- <label class="control-label" for="contact-time">Preferred Contact Time</label>
- <select class="selectpicker contact-time" id="contact-time" name="contact-time" title="Preferred Contact Time">
- <option value="Morning">Morning (9-11am)</option>
- <option value="Afternoon">Afternoon (11-2pm)</option>
- <option value="Evening">Evening (2-5pm)</option>
- </select>
- <label class="control-label" for="contact-method">Preferred Contact Method</label>
- <select class="selectpicker contact-method" id="contact-method" name="contact-method" title="Preferred Contact Method">
- <option>By Phone</option>
- <option>By Email</option>
- </select>
- </div>
- </fieldset>
- </div>
- </div>
- </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement