Advertisement
Guest User

contact-form

a guest
Jul 18th, 2017
491
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.64 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 = 'youremail@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 = 'Gym - Contact Message';
  22.  
  23. $fields = array(
  24.     0 => array(
  25.         'text' => 'Name',
  26.         'val' => $_POST['name']
  27.     ),
  28.     1 => array(
  29.         'text' => 'Email address',
  30.         'val' => $_POST['email']
  31.     ),
  32.     2 => array(
  33.         'text' => 'Phone',
  34.         'val' => $_POST['phone']
  35.     ),
  36.     3 => array(
  37.         'text' => 'Message',
  38.         'val' => $_POST['message']
  39.     )
  40. );
  41.  
  42. $message = '';
  43.  
  44. foreach($fields as $field) {
  45.     $message .= $field['text'].": " . htmlspecialchars($field['val'], ENT_QUOTES) . "<br>\n";
  46. }
  47.  
  48. $mail = new PHPMailer(true);
  49.  
  50. try {
  51.  
  52.     $mail->SMTPDebug = $debug;                                 // Debug Mode
  53.  
  54.     // Step 2 (Optional) - If you don't receive the email, try to configure the parameters below:
  55.  
  56.     //$mail->IsSMTP();                                         // Set mailer to use SMTP
  57.     //$mail->Host = 'mail.yourserver.com';                     // Specify main and backup server
  58.     //$mail->SMTPAuth = true;                                  // Enable SMTP authentication
  59.     //$mail->Username = 'user@example.com';                    // SMTP username
  60.     //$mail->Password = 'secret';                              // SMTP password
  61.     //$mail->SMTPSecure = 'tls';                               // Enable encryption, 'ssl' also accepted
  62.     //$mail->Port = 587;                                       // TCP port to connect to
  63.  
  64.     $mail->AddAddress($email);                                 // Add another recipient
  65.  
  66.     //$mail->AddAddress('person2@domain.com', 'Person 2');     // Add a secondary recipient
  67.     //$mail->AddCC('person3@domain.com', 'Person 3');          // Add a "Cc" address.
  68.     //$mail->AddBCC('person4@domain.com', 'Person 4');         // Add a "Bcc" address.
  69.  
  70.     $mail->SetFrom($email, $_POST['name']);
  71.     $mail->AddReplyTo($_POST['email'], $_POST['name']);
  72.  
  73.     $mail->IsHTML(true);                                  // Set email format to HTML
  74.  
  75.     $mail->CharSet = 'UTF-8';
  76.  
  77.     $mail->Subject = $subject;
  78.     $mail->Body    = $message;
  79.  
  80.     $mail->Send();
  81.     $arrResult = array ('response'=>'success');
  82.  
  83. } catch (phpmailerException $e) {
  84.     $arrResult = array ('response'=>'error','errorMessage'=>$e->errorMessage());
  85. } catch (Exception $e) {
  86.     $arrResult = array ('response'=>'error','errorMessage'=>$e->getMessage());
  87. }
  88.  
  89. if ($debug == 0) {
  90.     echo json_encode($arrResult);
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement