SHARE
TWEET

php

a guest May 23rd, 2018 203 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /*
  3. Name:           Contact Form
  4. Written by:     Okler Themes - (http://www.okler.net)
  5. Theme Version:  6.1.0
  6. */
  7. error_reporting(E_ALL ^ E_NOTICE);
  8.  
  9. session_cache_limiter('nocache');
  10. header('Expires: ' . gmdate('r', 0));
  11.  
  12. header('Content-type: application/json');
  13.  
  14. require_once('php-mailer/PHPMailerAutoload.php');
  15.  
  16. // Step 1 - Enter your email address below.
  17. $email = 'you@domain.com';
  18.  
  19. // If the e-mail is not working, change the debug option to 2 | $debug = 2;
  20. $debug = 0;
  21.  
  22. $subject = ( isset($_POST['subject']) ) ? $_POST['subject'] : '';
  23.  
  24. $fields = array(
  25.     0 => array(
  26.         'text' => 'Name',
  27.         'val' => ( isset($_POST['name']) ) ? $_POST['name'] : ''
  28.     ),
  29.     1 => array(
  30.         'text' => 'Email address',
  31.         'val' => ( isset($_POST['email']) ) ? $_POST['email'] : ''
  32.     ),
  33.     2 => array(
  34.         'text' => 'Message',
  35.         'val' => ( isset($_POST['message']) ) ? $_POST['message'] : ''
  36.     )
  37. );
  38.  
  39. $message = '';
  40.  
  41. foreach($fields as $field) {
  42.     $message .= $field['text'].": " . htmlspecialchars($field['val'], ENT_QUOTES) . "<br>\n";
  43. }
  44.  
  45. // $name = ( isset($_POST['name']) ) ? $_POST['name'] : '';
  46. // $user_email = ( isset($_POST['name']) ) ? $_POST['name'] : '';
  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, $name);
  71.     $mail->AddReplyTo($user_email, $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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top