Advertisement
marrow

код

May 30th, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  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 = 'arefyev.studio@gmail.com';
  11.  
  12. $subject = $_POST['subject'];
  13.  
  14. if($to) {
  15.  
  16. $name = $_POST['name'];
  17. $email = $_POST['email'];
  18.  
  19. $fields = array(
  20. 0 => array(
  21. 'text' => 'Name',
  22. 'val' => $_POST['name']
  23. ),
  24. 1 => array(
  25. 'text' => 'Email address',
  26. 'val' => $_POST['email']
  27. ),
  28. 2 => 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;
  41.  
  42. $mail->IsSMTP(); // Set mailer to use SMTP
  43.  
  44. // Optional Settings
  45. //$mail->Host = 'mail.yourserver.com'; // Specify main and backup server
  46. //$mail->SMTPAuth = true; // Enable SMTP authentication
  47. //$mail->Username = 'username'; // SMTP username
  48. //$mail->Password = 'secret'; // SMTP password
  49. //$mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted
  50.  
  51. $mail->From = $email;
  52. $mail->FromName = $_POST['name'];
  53. $mail->AddAddress($to); // Add a recipient
  54. $mail->AddReplyTo($email, $name);
  55.  
  56. $mail->IsHTML(true); // Set email format to HTML
  57.  
  58. $mail->CharSet = 'UTF-8';
  59.  
  60. $mail->Subject = $subject;
  61. $mail->Body = $message;
  62.  
  63. if(!$mail->Send()) {
  64. $arrResult = array ('response'=>'error');
  65. }
  66.  
  67. $arrResult = array ('response'=>'success');
  68.  
  69. echo json_encode($arrResult);
  70.  
  71. } else {
  72.  
  73. $arrResult = array ('response'=>'error');
  74. echo json_encode($arrResult);
  75.  
  76. }
  77. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement