Ravshan Abdurasulov Ravshan Abdurasulov - 1 year ago 83
Ajax Question

Jquery empty results


I tried after submitting the form not redirect to email php. For that I used ajax and its somehow working however it's gives back empty result. I have problem with javascript but thats enough difficult to find for my beginner level. I tested to send email without ajax and it sending normally. But redirecting to empty page email.php


<form method="POST" id="myForm" data-toggle="validator" action="email.php">
<h2 class="section-heading">Свяжитесь с нами:</h2>
<div class="form-group">
<label for="exampleInputEmail1">Имя:</label>
<input style="background:none;" id="firstName" name="firtname" class="form-control" placeholder="Имя" required>
<p id="p1"></p>
<div class="form-group">
<label for="exampleInputEmail1">Тема:</label>
<input style="background:none;" id="subjectTheme" name="subject" class="form-control" placeholder="Тема" required>
<p id="p2"></p>
<div class="form-group">
<label for="exampleInputEmail1">Электронная почта:</label>
<input style="background:none;" type="email" id="email" name="email" class="form-control" placeholder="Электронная почта" required>
<p class="help-block with-errors"></p>
<div class="form-group">
<textarea style="background:none;" name="message" class="form-control" rows="3"></textarea>
<input type="submit" id="sendButton" class="btn btn-default"/>


$('#myForm').submit(function(e) {
type: 'POST',
url: 'email.php'




$to = 'test@mail.ru'; // Replace with your email

$subject = $_POST['subject']; // Replace with your $subject
$headers = 'From: ' . $_POST['email'];

$message = 'Имя: ' . $_POST['firtname'] . "\n" .
'Электронная почта: ' . $_POST['email'] . "\n" .
'Тема: ' . $_POST['subject'] . "\n" .
'Сообщение: ' . $_POST['message'];

mail($to, $subject, $message, $headers);


Answer Source

You need to pass the content of the form

$('#myForm').on("submit",function(e) {
    function(response) { 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download