Advertisement
Guest User

Untitled

a guest
May 30th, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. session_cache_limiter('nocache');
  3. header('Expires: ' . gmdate('r', 0));
  4.  
  5. header('Content-type: application/json');
  6.  
  7. require 'php-mailer/class.phpmailer.php';
  8.  
  9. // Your email address
  10. $to = [
  11.     'arefyev.studio@gmail.com',
  12.     'hello@domain.com'
  13. ];
  14.  
  15. $subject = $_POST['subject'];
  16.  
  17. if(!empty($to)) {
  18.  
  19.     $name = $_POST['name'];
  20.     $email = $_POST['email'];
  21.    
  22.     $fields = array(
  23.         0 => array(
  24.             'text' => 'Name',
  25.             'val' => $_POST['name']
  26.         ),
  27.         1 => array(
  28.             'text' => 'Email address',
  29.             'val' => $_POST['email']
  30.         ),
  31.         2 => array(
  32.             'text' => 'Message',
  33.             'val' => $_POST['message']
  34.         )
  35.     );
  36.    
  37.     $message = "";
  38.    
  39.     foreach($fields as $field) {
  40.         $message .= $field['text'].": " . htmlspecialchars($field['val'], ENT_QUOTES) . "<br>\n";
  41.     }
  42.    
  43.     $mail = new PHPMailer;
  44.  
  45.     $mail->IsSMTP();                                      // Set mailer to use SMTP
  46.    
  47.     // Optional Settings
  48.     //$mail->Host = 'mail.yourserver.com';                // Specify main and backup server
  49.     //$mail->SMTPAuth = true;                             // Enable SMTP authentication
  50.     //$mail->Username = 'username';                       // SMTP username
  51.     //$mail->Password = 'secret';                         // SMTP password
  52.     //$mail->SMTPSecure = 'tls';                          // Enable encryption, 'ssl' also accepted
  53.  
  54.     $mail->From = $email;
  55.     $mail->FromName = $_POST['name'];
  56.     foreach ($to as $one_to) {
  57.         $mail->AddAddress($one_to);                               // Add a recipient
  58.     }
  59.     $mail->AddReplyTo($email, $name);
  60.  
  61.     $mail->IsHTML(true);                                  // Set email format to HTML
  62.    
  63.     $mail->CharSet = 'UTF-8';
  64.  
  65.     $mail->Subject = $subject;
  66.     $mail->Body    = $message;
  67.  
  68.     if(!$mail->Send()) {
  69.        $arrResult = array ('response'=>'error');
  70.     }
  71.  
  72.     $arrResult = array ('response'=>'success');
  73.  
  74.     echo json_encode($arrResult);
  75.    
  76. } else {
  77.  
  78.     $arrResult = array ('response'=>'error');
  79.     echo json_encode($arrResult);
  80.  
  81. }
  82. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement