Advertisement
Guest User

php

a guest
Jul 16th, 2018
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.13 KB | None | 0 0
  1. <?php
  2. /*
  3. Name:           Contact Form
  4. Written by:     Okler Themes - (http://www.okler.net)
  5. Theme Version:  6.2.1
  6. */
  7.  
  8. session_cache_limiter('nocache');
  9. header('Expires: ' . gmdate('r', 0));
  10.  
  11. header('Content-type: application/json');
  12.  
  13. require_once('php-mailer/PHPMailerAutoload.php');
  14.  
  15. // Step 1 - Enter your email address below.
  16. $email = 'you@domain.com';
  17.  
  18. // If the e-mail is not working, change the debug option to 2 | $debug = 2;
  19. $debug = 0;
  20.  
  21. $subject = 'Hotel Book Reservation Form';
  22.  
  23. $fields = array(
  24.     0 => array(
  25.         'text' => 'Arrival',
  26.         'val' => $_POST['arrival']
  27.     ),
  28.     1 => array(
  29.         'text' => 'Departure',
  30.         'val' => $_POST['departure']
  31.     ),
  32.     2 => array(
  33.         'text' => 'Adults',
  34.         'val' => $_POST['adults']
  35.     ),
  36.     3 => array(
  37.         'text' => 'Kids',
  38.         'val' => $_POST['kids']
  39.     ),
  40.     4 => array(
  41.         'text' => 'Room',
  42.         'val' => $_POST['room']
  43.     ),
  44.     5 => array(
  45.         'text' => 'Full Name',
  46.         'val' => $_POST['fullname']
  47.     ),
  48.     6 => array(
  49.         'text' => 'Address 1',
  50.         'val' => $_POST['address1']
  51.     ),
  52.     7 => array(
  53.         'text' => 'Address 2',
  54.         'val' => $_POST['address2']
  55.     ),
  56.     8 => array(
  57.         'text' => 'City',
  58.         'val' => $_POST['city']
  59.     ),
  60.     9 => array(
  61.         'text' => 'State',
  62.         'val' => $_POST['state']
  63.     ),
  64.     10 => array(
  65.         'text' => 'Zip',
  66.         'val' => $_POST['zip']
  67.     )
  68. );
  69.  
  70. $message = '';
  71.  
  72. foreach($fields as $field) {
  73.     $message .= $field['text'].": " . htmlspecialchars($field['val'], ENT_QUOTES) . "<br>\n";
  74. }
  75.  
  76. $mail = new PHPMailer(true);
  77.  
  78. try {
  79.  
  80.     $mail->SMTPDebug = $debug;                                 // Debug Mode
  81.  
  82.     // Step 2 (Optional) - If you don't receive the email, try to configure the parameters below:
  83.  
  84.     //$mail->IsSMTP();                                         // Set mailer to use SMTP
  85.     //$mail->Host = 'mail.yourserver.com';                     // Specify main and backup server
  86.     //$mail->SMTPAuth = true;                                  // Enable SMTP authentication
  87.     //$mail->Username = 'user@example.com';                    // SMTP username
  88.     //$mail->Password = 'secret';                              // SMTP password
  89.     //$mail->SMTPSecure = 'tls';                               // Enable encryption, 'ssl' also accepted
  90.     //$mail->Port = 587;                                       // TCP port to connect to
  91.  
  92.     $mail->AddAddress($email);                                 // Add another recipient
  93.  
  94.     //$mail->AddAddress('person2@domain.com', 'Person 2');     // Add a secondary recipient
  95.     //$mail->AddCC('person3@domain.com', 'Person 3');          // Add a "Cc" address.
  96.     //$mail->AddBCC('person4@domain.com', 'Person 4');         // Add a "Bcc" address.
  97.  
  98.     $mail->SetFrom($email, $_POST['name']);
  99.     $mail->AddReplyTo($_POST['email'], $_POST['name']);
  100.  
  101.     $mail->IsHTML(true);                                  // Set email format to HTML
  102.  
  103.     $mail->CharSet = 'UTF-8';
  104.  
  105.     $mail->Subject = $subject;
  106.     $mail->Body    = $message;
  107.  
  108.     $mail->Send();
  109.     $arrResult = array ('response'=>'success');
  110.  
  111. } catch (phpmailerException $e) {
  112.     $arrResult = array ('response'=>'error','errorMessage'=>$e->errorMessage());
  113. } catch (Exception $e) {
  114.     $arrResult = array ('response'=>'error','errorMessage'=>$e->getMessage());
  115. }
  116.  
  117. if ($debug == 0) {
  118.     echo json_encode($arrResult);
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement