Guest User

Untitled

a guest
Nov 24th, 2016
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.73 KB | None | 0 0
  1. <?php
  2. /*
  3. Name:           Contact Form
  4. Written by:     Okler Themes - (http://www.okler.net)
  5. Version:        4.3.1
  6. */
  7.  
  8. session_cache_limiter('nocache');
  9. header('Expires: ' . gmdate('r', 0));
  10.  
  11. header('Content-type: application/json');
  12.  
  13. // Step 1 - Enter your email address below.
  14. $to = 'contact@tomexdev.com';
  15.  
  16. // Step 2 - Enable if the server requires SMTP authentication. (true/false)
  17. $enablePHPMailer = true;
  18.  
  19. $subject = $_POST['subject'];
  20.  
  21. if(isset($_POST['email'])) {
  22.  
  23.     $name = $_POST['name'];
  24.     $email = $_POST['email'];
  25.  
  26.     $fields = array(
  27.         0 => array(
  28.             'text' => 'Name',
  29.             'val' => $_POST['name']
  30.         ),
  31.         1 => array(
  32.             'text' => 'Email address',
  33.             'val' => $_POST['email']
  34.         ),
  35.         2 => array(
  36.             'text' => 'Message',
  37.             'val' => $_POST['message']
  38.         )
  39.     );
  40.  
  41.     $message = "";
  42.  
  43.     foreach($fields as $field) {
  44.         $message .= $field['text'].": " . htmlspecialchars($field['val'], ENT_QUOTES) . "<br>\n";
  45.     }
  46.  
  47.     // Simple Mail
  48.     if(!$enablePHPMailer) {
  49.  
  50.         $headers = '';
  51.         $headers .= 'From: ' . $name . ' <' . $email . '>' . "\r\n";
  52.         $headers .= "Reply-To: " .  $email . "\r\n";
  53.         $headers .= "MIME-Version: 1.0\r\n";
  54.         $headers .= "Content-Type: text/html; charset=UTF-8\r\n";
  55.  
  56.         if (mail($to, $subject, $message, $headers)){
  57.             $arrResult = array ('response'=>'success');
  58.         } else{
  59.             $arrResult = array ('response'=>'error');
  60.         }
  61.  
  62.     // PHP Mailer Library - Docs: https://github.com/PHPMailer/PHPMailer
  63.     } else {
  64.  
  65.         include("php-mailer/PHPMailerAutoload.php");
  66.  
  67.         $mail = new PHPMailer;
  68.  
  69.         $mail->IsSMTP();                                      // Set mailer to use SMTP
  70.         $mail->SMTPDebug = 0;                                 // Debug Mode
  71.  
  72.         // Step 3 - If you don't receive the email, try to configure the parameters below:
  73.  
  74.         $mail->Host = 'us.hostblast.net';                 // Specify main and backup server
  75.         $mail->SMTPAuth = true;                             // Enable SMTP authentication
  76.         $mail->Username = 'contact@tomexdev.com';                     // SMTP username
  77.         $mail->Password = 'dinamo1986!';                         // SMTP password
  78.         $mail->SMTPSecure = 'ssl';                          // Enable encryption, 'ssl' also accepted
  79.  
  80.         $mail->From = $email;
  81.         $mail->FromName = $_POST['name'];
  82.         $mail->AddAddress($to);                               // Add a recipient
  83.         $mail->AddReplyTo($email, $name);
  84.  
  85.         $mail->IsHTML(true);                                  // Set email format to HTML
  86.  
  87.         $mail->CharSet = 'UTF-8';
  88.  
  89.         $mail->Subject = $subject;
  90.         $mail->Body    = $message;
  91.  
  92.         if(!$mail->Send()) {
  93.            $arrResult = array ('response'=>'error');
  94.         }
  95.  
  96.         $arrResult = array ('response'=>'success');
  97.  
  98.     }
  99.  
  100.     echo json_encode($arrResult);
  101.  
  102. } else {
  103.  
  104.     $arrResult = array ('response'=>'error');
  105.     echo json_encode($arrResult);
  106.  
  107. }
  108. ?>
Add Comment
Please, Sign In to add comment