Advertisement
Guest User

Untitled

a guest
Mar 16th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. <?php
  2. require_once 'PHPMailer_5.2.4/class.phpmailer.php';
  3. require_once 'PHPMailer_5.2.4/class.smtp.php';
  4.  
  5. if ($_POST) {
  6. $name = htmlspecialchars($_POST["name"]);
  7. $email = htmlspecialchars($_POST["email"]);
  8. $subject = htmlspecialchars($_POST["subject"]);
  9. $message = htmlspecialchars($_POST["message"]);
  10. $json = array();
  11. if (!$name or !$email or !$subject or !$message) {
  12. $json['error'] = 'Вы зaпoлнили нe всe пoля! oбмaнуть рeшили? =)';
  13. echo json_encode($json);
  14. die();
  15. }
  16. if (!preg_match("|^[-0-9a-z_\.]+@[-0-9a-z_^\.]+\.[a-z]{2,6}$|i", $email)) {
  17. $json['error'] = 'Нe вeрный фoрмaт email! >_<'; // пишeм oшибку в мaссив
  18. echo json_encode($json);
  19. die();
  20. }
  21.  
  22. function mime_header_encode($str, $data_charset, $send_charset)
  23. {
  24. if ($data_charset != $send_charset)
  25. $str = iconv($data_charset, $send_charset . '//IGNORE', $str);
  26. return ('=?' . $send_charset . '?B?' . base64_encode($str) . '?=');
  27. }
  28.  
  29. $mail = new PHPMailer(true);
  30.  
  31. $mail->IsSMTP();
  32. $mail->Host = "smtp.gmail.com";
  33. $mail->SMTPAuth = true;
  34. $mail->SMTPSecure = 'ssl';
  35. $mail->Port = 465;
  36. $mail->CharSet = 'UTF-8';
  37.  
  38. $body = $_POST['message'];
  39. $mail->Username = "newj**@gmail.com";
  40. $mail->Password = "pass";
  41. $mail->SetFrom('smy**@gmail.com', 'N B');
  42. $mail->Subject = $_POST['subject'];
  43. $mail->msgHTML($body);
  44. $mail->addAddress('newj**@gmail.com', 'N B');
  45.  
  46. if ($mail->Send()) {
  47. echo "Message sent";
  48. } else {
  49. echo "ERROR: " . $mail->ErrorInfo;
  50. }
  51. echo json_encode($mail);
  52. $json['error'] = 0;
  53.  
  54. echo json_encode($json);
  55. } else {
  56. echo 'Массив не был передан!';
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement