Here is the form itself

<form id="contact-form" method="post" class="single-form" action="php/mail.php"> <div class="message col-xs-12"> <div class="inner"> <p class="email-loading"><img src="images/loading.gif" alt="">&nbsp;&nbsp;&nbsp;Sending...</p> <p class="email-success"><i class="icon icon-icon-check-alt2"></i> Your quote has successfully been sent.</p> <p class="email-failed"><i class="icon icon-icon-close-alt2"></i> Something went wrong!</p> </div> <!-- End: .inner --> </div> <!-- End: .message --> <div class="col-sm-4"> <input name="name" class="contact-name form-control" id="contact-name" type="text" placeholder="Name" required=""> </div> <div class="col-sm-4"> <input name="email" class="contact-email form-control" id="contact-email" type="email" placeholder="Email" required=""> </div> <div class="col-sm-4"> <input name="Phone" class="contact-name2 form-control" id="Phone" type="text" placeholder="Phone" required=""> </div> <div class="col-sm-12"> <input name="subject" class="contact-subject form-control" id="contact-subject" type="text" placeholder="Subject" required=""> </div> <div class="col-sm-12"> <textarea name="message" class="contact-message form-control" id="contact-message" rows="3" placeholder="Message" required=""></textarea> </div> <!-- Subject Button --> <div class="btn-form text-center col-xs-12"> <button class="btn btn-fill right-icon">отправить сообщение<i class="icon icons8-advance"></i></button> </div> </form> 

But the handler

 <?php // Variables $name = trim($_POST['name']); $email = trim($_POST['email']); $Phone = trim($_POST['Phone']); $subject = trim($_POST['subject']); $message = trim($_POST['message']); if( isset($name) ) { // Avoid Email Injection and Mail Form Script Hijacking $pattern = "/(content-type|bcc:|cc:|to:)/i"; if( preg_match($pattern, $name) || preg_match($pattern, $message) ) { exit; } // Email will be send $to = "molchanov.artem.1994@gmail.com"; //$to = "hrolenko.a@gmail.com"; // innaeger@gmail.com Change with your email address $sub = "$subject from Cv"; // You can define email subject // HTML Elements for Email Body $body = ' Имя отправителя:'.$name.' Контактный телефон:'.$Phone.' Контактный email:'.$email.' Сообщение:'.$message; //Must end on first column $headers = "Заявка на инсталляцию: $name\r\n"; $headers .= 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // PHP email sender mail($to, $sub, $body, $headers); } ?> 

Js

 $("#contact-form").on('submit', function(e) { e.preventDefault(); var success = $(this).find('.email-success'), failed = $(this).find('.email-failed'), loader = $(this).find('.email-loading'), postUrl = $(this).attr('action'); var data = { name: $(this).find('.contact-name').val(), email: $(this).find('.contact-email').val(), phone: $(this).find('.contact-phone').val(), subject: $(this).find('.contact-subject').val(), message: $(this).find('.contact-message').val() }; if ( isValidEmail(data['email']) && (data['message'].length > 1) && (data['name'].length > 1) ) { $.ajax({ type: "POST", url: postUrl, data: data, beforeSend: function() { loader.fadeIn(1000); }, success: function(data) { loader.fadeOut(1000); success.delay(500).fadeIn(1000); failed.fadeOut(500); }, error: function(xhr) { // if error occured loader.fadeOut(1000); failed.delay(500).fadeIn(1000); success.fadeOut(500); }, complete: function() { loader.fadeOut(1000); } }); } else { loader.fadeOut(1000); failed.delay(500).fadeIn(1000); success.fadeOut(500); } return false; }); 
  • You can try to check in the handler Phone print_r ($ _ POST ['Phone'])); exit (); Does the value of the phone reach the handler? - Arsen
  • @Arsen does not reach, I do not understand why - Artyom Molchanov
  • Clearly, it can try to change the name = 'phone ", theoretically there should be no difference, if it is not difficult to change it <input name =" phone "class =" contact-name2 form-control "id =" Phone "type =" text "placeholder = "Phone" required = ""> - Arsen
  • checked your example with the form tag <form action = "/ indexes.php" method = "POST">, everything worked, you could not display your form tag - LeshaZ
  • @LeshaZ <form id = "contact-form" method = "post" class = "single-form" action = "php / sendmail.php"> - Artyom Molchanov

2 answers 2

Judging by the responses in the comments, you should

1) Fix it in <input name="Phone" class="contact-name2 form-control" id="Phone" type="text" placeholder="Phone" required=""> class contact-name2 on contact-phone

2) On the server side, fix the Phone key on the phone or on the js side in the data object, fix the phone on the Phone

     var data = { name: $(this).find('.contact-name').val(), email: $(this).find('.contact-email').val(), phone: $(this).find('.contact-phone').val(), // В этой строчке ошибка. Нужно phone: $(this).find('.contact-name2').val() subject: $(this).find('.contact-subject').val(), message: $(this).find('.contact-message').val() }; 

    There is no .contact-phone in the form. Therefore, an empty value is sent to the server.

    In php file you need to replace

     $Phone = trim($_POST['Phone']); на $Phone = trim($_POST['phone']);