Advertisement
Guest User

php

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