Advertisement
Guest User

contact-form.php

a guest
Jul 4th, 2017
503
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.05 KB | None | 0 0
  1. <?php
  2. /*
  3. Name:           Contact Form
  4. Written by:     Okler Themes - (http://www.okler.net)
  5. Theme Version:  5.7.2
  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 = 'info@salvatorepumo.it';
  17.  
  18. // If the e-mail is not working, change the debug option to 2 | $debug = 2;
  19. $debug = 0;
  20.  
  21. if( $_POST['message'] ) { // Concat Form Fields will be sent
  22.  
  23.     $subject = 'Gym - Contact Message';
  24.  
  25.     $fields = array(
  26.         0 => array(
  27.             'text' => 'Name',
  28.             'val' => $_POST['name']
  29.         ),
  30.         1 => array(
  31.             'text' => 'Email address',
  32.             'val' => $_POST['email']
  33.         ),
  34.         3 => array(
  35.             'text' => 'Phone',
  36.             'val' => $_POST['phone']
  37.         ),
  38.         4 => array(
  39.             'text' => 'Message',
  40.             'val' => $_POST['message']
  41.         )
  42.     );
  43.  
  44. } else { // VIP Request field will be sent
  45.  
  46.     $subject = 'Gym - VIP Request';
  47.  
  48.     $fields = array(
  49.         0 => array(
  50.             'text' => 'Name',
  51.             'val' => $_POST['name']
  52.         ),
  53.         1 => array(
  54.             'text' => 'Email address',
  55.             'val' => $_POST['email']
  56.         ),
  57.         2 => array(
  58.             'text' => 'Phone',
  59.             'val' => $_POST['phone']
  60.         )
  61.     );
  62.  
  63. }
  64.  
  65. $message = '';
  66.  
  67. foreach($fields as $field) {
  68.     $message .= $field['text'].": " . htmlspecialchars($field['val'], ENT_QUOTES) . "<br>\n";
  69. }
  70.  
  71. $mail = new PHPMailer(true);
  72.  
  73. try {
  74.  
  75.     $mail->SMTPDebug = $debug;                                 // Debug Mode
  76.  
  77.     // Step 2 (Optional) - If you don't receive the email, try to configure the parameters below:
  78.  
  79.     //$mail->IsSMTP();                                         // Set mailer to use SMTP
  80.     //$mail->Host = 'mail.yourserver.com';                     // Specify main and backup server
  81.     //$mail->SMTPAuth = true;                                  // Enable SMTP authentication
  82.     //$mail->Username = 'user@example.com';                    // SMTP username
  83.     //$mail->Password = 'secret';                              // SMTP password
  84.     //$mail->SMTPSecure = 'tls';                               // Enable encryption, 'ssl' also accepted
  85.     //$mail->Port = 587;                                       // TCP port to connect to
  86.  
  87.     $mail->AddAddress($email);                                 // Add another recipient
  88.  
  89.     //$mail->AddAddress('person2@domain.com', 'Person 2');     // Add a secondary recipient
  90.     //$mail->AddCC('person3@domain.com', 'Person 3');          // Add a "Cc" address.
  91.     //$mail->AddBCC('person4@domain.com', 'Person 4');         // Add a "Bcc" address.
  92.  
  93.     $mail->SetFrom($email, $_POST['name']);
  94.     $mail->AddReplyTo($_POST['email'], $_POST['name']);
  95.  
  96.     $mail->IsHTML(true);                                  // Set email format to HTML
  97.  
  98.     $mail->CharSet = 'UTF-8';
  99.  
  100.     $mail->Subject = $subject;
  101.     $mail->Body    = $message;
  102.  
  103.     $mail->Send();
  104.     $arrResult = array ('response'=>'success');
  105.  
  106. } catch (phpmailerException $e) {
  107.     $arrResult = array ('response'=>'error','errorMessage'=>$e->errorMessage());
  108. } catch (Exception $e) {
  109.     $arrResult = array ('response'=>'error','errorMessage'=>$e->getMessage());
  110. }
  111.  
  112. if ($debug == 0) {
  113.     echo json_encode($arrResult);
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement