Advertisement
Guest User

Untitled

a guest
Feb 19th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. <form action="" method="POST" id="askform">
  2. <table>
  3. <tr>
  4. <td>Имя</td><td><input type="text" name="name" placeholder="Иванов Иван Иванович" required pattern="^[А-Яа-яЁё ]+$"></td>
  5. </tr>
  6. <tr>
  7. <td>E-mail</td><td><input name="email" placeholder="example@gmail.com" required type="email"></td>
  8. </tr>
  9. <tr>
  10. <td>Вопрос</td><td><textarea type="text" name="question" placeholder="Опишите, что Вас интересует" required></textarea></td>
  11. </tr>
  12. </table>
  13. <input id="doask" type="submit" value="Отправить"/>
  14. </form>
  15. <script>
  16. $(document).ready(function(){
  17. $("#askform").submit(function() {
  18. var form_data = $(this).serialize();
  19. $.ajax({
  20. type: "POST",
  21. url: "php/ask.php",
  22. data: form_data,
  23. success: function() {
  24. alert('Успешно');
  25. },
  26. error: function() {
  27. alert('возникла ошибка');
  28. };
  29. return false;
  30. });
  31. });
  32. });
  33. </script>
  34.  
  35. <?php
  36. if((isset($_POST['name'])&&$_POST['name']!="")&&(isset($_POST['email'])&&$_POST['email']!="")
  37. &&(isset($_POST['question'])&&$_POST['question']!="")){
  38. $to = 'testmail@gmail.com';
  39. $subject = 'Вопрос';
  40. $name = $_POST['name'];
  41. $email = $_POST['email'];
  42. $question = $_POST['question'];
  43. $message='
  44. <html>
  45. <head>
  46. <title>'.$subject.'</title>
  47. </head>
  48. <body>
  49. <p>Имя: '.$name.'</p>
  50. <p>email: '.$email.'</p>
  51. <p>Вопрос: '.$question.'</p>
  52. </body>
  53. </html>';
  54. $headers = "Content-type: text/html; charset=utf-8 rn";
  55. $headers .= "From: testmail@gmail.comrn";
  56. mail($to, $subject, $message, $headers);
  57. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement