Advertisement
Guest User

contact-form

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