Guest User

Untitled

a guest
Feb 6th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.14 KB | None | 0 0
  1. $(document).ready(function() {
  2. $('#phone').inputmask("+7(999)999-99-99", {
  3. showMaskOnHover: false,
  4. showMaskOnFocus: true
  5. });
  6.  
  7. $('#feedback').validate({
  8. rules: {
  9. name: {
  10. required: true
  11. },
  12. phone: {
  13. phoneRUS: true,
  14. required: true
  15. },
  16. email: {
  17. required: true,
  18. email: true
  19. }
  20. },
  21. messages: {
  22. name: {
  23. required: "Вы не заполнили поле"
  24. },
  25. phone: {
  26. required: "Вы не заполнили поле"
  27. },
  28. email: {
  29. required: "Вы не заполнили поле"
  30. }
  31. }
  32. });
  33.  
  34. $('#feedback').submit(function() {
  35. var form = $(this);
  36. var error = false;
  37.  
  38. if (!error) {
  39. var data = form.serialize();
  40. $.ajax({
  41. type: 'POST',
  42. url: '/contacts/mailer.php',
  43. dataType: 'json',
  44. data: data,
  45. success: function(data) {
  46. //console.log(data);
  47. if (!data['error']) {
  48. $('.valid-text').text('Сообщение отправлено, мы с вами обязательно свяжемся').fadeIn('fast');
  49. //echo('Ваша заявка отправлена');
  50. }
  51. },
  52. error: function(xhr, ajaxOptions, thrownError) {
  53. console.log(xhr.status);
  54. console.log(thrownError);
  55. }
  56. });
  57. }
  58. return false;
  59. });
  60. });
  61.  
  62. <? php
  63.  
  64. include_once 'vendor/swiftmailer/swiftmailer/lib/swift_required.php';
  65.  
  66. $name = htmlspecialchars(strip_tags($_POST["name"]));
  67. $phone = htmlspecialchars(strip_tags($_POST["phone"]));
  68. $email = htmlspecialchars(strip_tags($_POST["email"]));
  69. $text = htmlspecialchars(strip_tags($_POST["message"]));
  70. $file = $_FILES['file'];
  71.  
  72. $errors = array();
  73.  
  74. if (empty($name)) {
  75. $errors["name"] = "Не заполнено поле";
  76. }
  77.  
  78. if (empty($phone)) {
  79. $errors["phone"] = "Не заполнено поле";
  80. }
  81.  
  82. if (empty($email)) {
  83. $errors["email"] = "Не заполнено поле";
  84. }
  85.  
  86. if (!empty($errors)) {
  87. $errors = json_encode(array('success' => true, 'errors' => $errors));
  88. }
  89.  
  90. $subject = 'Сообщение с сайта legiteam.ru';
  91. $from = array('no-reply@****.ru');
  92. $to = array(
  93. '*******@gmail.com' => 'Evgeniy',
  94. $email // ОПАСНОСТЬ?
  95. );
  96.  
  97. $html = "<h3>$subject</h3><p>Ваша заявка успешно доставлена и будет обработана в ближайшее время.</p>
  98. <p>Текст заявки: $text</p>
  99. <p>Имя: $name</p>
  100. <p>Телефон: $phone</p>
  101. <p>E-mail: $email</p>";
  102.  
  103. $transport = Swift_MailTransport::newInstance();
  104.  
  105. $mailer = Swift_Mailer::newInstance($transport);
  106.  
  107.  
  108. $message = Swift_Message::newInstance();
  109. $message - > setSubject($subject);
  110. $message - > setFrom($from);
  111. $message - > setBody($html, 'text/html');
  112. $message - > setTo($to);
  113.  
  114. if (is_uploaded_file($_FILES['file']['tmp_name'])) {
  115. $message - > attach(Swift_Attachment::fromPath($_FILES['file']['tmp_name']) - > setFilename($_FILES['file']['name']));
  116. }
  117.  
  118. $numSent = $mailer - > send($message);
  119.  
  120. //if ($mailer->send($message))
  121. //{
  122. // echo "Сообщение отправлено";
  123. //}
  124. // else
  125. //{
  126. // echo "Не удалось отправить сообщение";
  127. //}
  128.  
  129. success: function(data) {
  130. //console.log(data); вот у вас это даже есть. и что оно тут отдавало? Наверное "Сообщение отправлено"? Соответственно и проверять надо не то как вы проверяли.
  131. if ($.trim(data) == 'ok') {
  132. $('.valid-text').text('Сообщение отправлено, мы с вами обязательно свяжемся').fadeIn('fast');
  133. } else {
  134. $('.valid-text').text('Сообщение не отправлено!').fadeIn('fast');
  135. }
  136. },
  137. error: function(xhr, ajaxOptions, thrownError) {
  138. console.log(xhr.status);
  139. console.log(thrownError);
  140. }
  141.  
  142. if ($mailer->send($message))
  143. {
  144. echo "ok";
  145. }
  146. else
  147. {
  148. echo "error";
  149. }
Add Comment
Please, Sign In to add comment