Advertisement
Guest User

Untitled

a guest
Nov 25th, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.80 KB | None | 0 0
  1. HTML
  2.  
  3. <div class="form">
  4. <div class="new-form">
  5. <form class="ajax-contact-form" action="" method="post" name="commentform" id="commentform" _lpchecked="1">
  6. <input type="text" name="author" id="author" value="" size="25" placeholder="Your name">
  7. <input type="text" name="email" id="email" value="" size="25" placeholder="Email">
  8. <textarea name="message" id="comment" cols="48" rows="8" placeholder="What are you needs? Include as much info as possible."></textarea>
  9. <input name="submit" type="submit" id="submit" value="Send" class="">
  10. </form>
  11. </div>
  12. </div>
  13.  
  14.  
  15. JS
  16.  
  17. $(".ajax-contact-form").submit(function() {
  18. var str = $(this).serialize();
  19. $.ajax({
  20. type: "POST",
  21. url: "contact.php",
  22. data: str,
  23. success: function(msg) {
  24. if(msg == 'OK') {
  25. result = '<p>Ваш заказ принят</p>';
  26. $(".fields").hide();
  27. } else {
  28. result = msg;
  29. }
  30. $('.note').html(result);
  31. }
  32. });
  33. return false;
  34. });
  35.  
  36. PHP
  37.  
  38. <?php
  39.  
  40. $post = (!empty($_POST)) ? true : false;
  41.  
  42. if($post)
  43. {
  44. $email = trim($_POST['email']);
  45. $author = htmlspecialchars($_POST['author']);
  46. $email = htmlspecialchars($_POST['email']);
  47. $message = htmlspecialchars($_POST['message']);
  48. $error = '';
  49.  
  50. if(!$author)
  51. {
  52. $error .= 'Пожалуйста введите ваше имя<br />';
  53. }
  54.  
  55. // Проверка телефона
  56. function ValidateTel($valueTel)
  57. {
  58. $regexTel = "/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/";
  59. if($valueTel == "") {
  60. return false;
  61. } else {
  62. $string = preg_replace($regexTel, "", $valueTel);
  63. }
  64. return empty($string) ? true : false;
  65. }
  66. if(!$email)
  67. {
  68. $error .= "Пожалуйста введите email<br />";
  69. }
  70. if($email && !ValidateTel($email))
  71. {
  72. $error .= "Введите корректный email<br />";
  73. }
  74. if(!$error)
  75.  
  76. // (length)
  77. if(!$message || strlen($message) < 1)
  78. {
  79. $error .= "Введите ваше сообщение<br />";
  80. }
  81. if(!$error)
  82. {
  83.  
  84.  
  85. $author_tema = "=?utf-8?b?". base64_encode($author) ."?=";
  86.  
  87. $subject ="Новая заявка с сайта precisecreative";
  88. $subject1 = "=?utf-8?b?". base64_encode($subject) ."?=";
  89. /*
  90. $message ="\n\nСообщение: ".$message."\n\nИмя: " .$author."\n\nТелефон: ".$tel."\n\n";
  91. */
  92. $message1 ="\n\nИмя: ".$author."\n\nТелефон: " .$tel."\n\nE-mail: " .$email."\n\nСообщение: ".$message."\n\n";
  93.  
  94.  
  95. $header = "Content-Type: text/plain; charset=utf-8\n";
  96.  
  97. $header .= "From: Новая заявка <[email protected]>\n\n";
  98. $mail = mail("[email protected]", $subject1, iconv ('utf-8', 'windows-1251', $message1), iconv ('utf-8', 'windows-1251', $header));
  99.  
  100. if($mail)
  101. {
  102. echo 'OK';
  103. }
  104.  
  105. }
  106. else
  107. {
  108. echo '<div class="notification_error">'.$error.'</div>';
  109. }
  110.  
  111. }
  112. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement