Good day. The topic is already beaten, but I'm still stupid.

The title seems to be all clear.

There is such Html:

<form action="" method="POST" id="askform"> <table> <tr> <td>Имя</td><td><input type="text" name="name" placeholder="Иванов Иван Иванович" required pattern="^[А-Яа-яЁё ]+$"></td> </tr> <tr> <td>E-mail</td><td><input name="email" placeholder="example@gmail.com" required type="email"></td> </tr> <tr> <td>Вопрос</td><td><textarea type="text" name="question" placeholder="Опишите, что Вас интересует" required></textarea></td> </tr> </table> <input id="doask" type="submit" value="Отправить"/> </form> <script> $(document).ready(function(){ $("#askform").submit(function() { var form_data = $(this).serialize(); $.ajax({ type: "POST", url: "php/ask.php", data: form_data, success: function() { alert('Успешно'); }, error: function() { alert('возникла ошибка'); }; return false; }); }); }); </script> 

And, accordingly, PHP:

 <?php if((isset($_POST['name'])&&$_POST['name']!="")&&(isset($_POST['email'])&&$_POST['email']!="") &&(isset($_POST['question'])&&$_POST['question']!="")){ $to = 'testmail@gmail.com'; $subject = 'Вопрос'; $name = $_POST['name']; $email = $_POST['email']; $question = $_POST['question']; $message=' <html> <head> <title>'.$subject.'</title> </head> <body> <p>Имя: '.$name.'</p> <p>email: '.$email.'</p> <p>Вопрос: '.$question.'</p> </body> </html>'; $headers = "Content-type: text/html; charset=utf-8 \r\n"; $headers .= "From: testmail@gmail.com\r\n"; mail($to, $subject, $message, $headers); ?> 

The sadness is that there is no message, and the page reloads. Where is my mistake?

Thank you in advance

  • Try another url: "./php/ask.php", - Bim Bam
  • And even with the code, the code was copied, but not quite identical. Try <textarea> for <input> swap. Sometimes this is the problem. - Bim Bam

1 answer 1

Try this:

 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <form action="" method="POST" id="askform"> <table> <tr> <td>Имя</td><td><input type="text" name="name" placeholder="Иванов Иван Иванович" required pattern="^[А-Яа-яЁё ]+$"></td> </tr> <tr> <td>E-mail</td><td><input name="email" placeholder="example@gmail.com" required type="email"></td> </tr> <tr> <td>Вопрос</td><td><textarea type="text" name="question" placeholder="Опишите, что Вас интересует" required></textarea></td> </tr> </table> <input id="doask" type="submit" value="Отправить"/> </form> <script> $(document).ready(function(){ $("#askform").submit(function() { var form_data = $(this).serialize(); $.ajax({ type: "POST", url: "ask.php", data: form_data, success: function () { alert('Успешно'); }, error: function () { alert('возникла ошибка'); } }); return false; }); }); </script> 

There was an error in javascript around "return false".

PHP is fine.

I sent the letter, the page was not overloaded, the message "Successful" appeared.

PS Bug JavaScript helps debug browser tool "Developer Tools".

  • And the letter does not go. is this the norm? - Blc_Dragon
  • I do not know. Looking at what you run ?? I came to Denwer in the Cage. - GHosT
  • Denver too, but silence - Blc_Dragon
  • I truly understand that the letter did not come to Denver at the address: localhost / Tests / sendmail / index.php ?? - GHosT
  • Remembered !! PHP lacks a closing brace at the end. - GHosT