I got the site HTML, CSS, Javascript, without a PHP file, which is responsible for sending information to the mail from the callback form. I try to write this file myself, but I lack experience. The letter arrives in the mail, the "Name" field is shown as needed, but the "Phone" and "Question" fields do not want to come. Please help me figure it out.

/* Adding blocks, transform blocks, only for correct display */ $(document).ready(function() { var prefix = $('.prefix').val(); var url = prefix + "respond.php"; $('.button').click(function() { $('body').find('form:not(this)').children('label').removeClass('red'); var request_url = '\n' + $('input[name="ref_url"]').val().toString().replace(/&/g, '\n'); var utm_source = $('input[name="ref_url"]').val().match(/(?:utm_source=)(.*)(?:&utm_medium)/i); var utm_medium = $('input[name="ref_url"]').val().match(/(?:utm_medium=)(.*)(?:&utm_campaign)/i); var utm_campaign = $('input[name="ref_url"]').val().match(/(?:utm_campaign=)(.*)(?:&utm_term)/i); var utm_term = $('input[name="ref_url"]').val().match(/(?:utm_term=)([0-9a-zA-Zа-яА-Я%]{1,})/i); if (utm_source == null || utm_medium == null || utm_campaign == null || utm_term == null) var utms = ''; else var utms = '\nutm_source=' + utm_source[1] + '\nutm_medium=' + utm_medium[1] + '\nutm_campaign=' + utm_campaign[1] + '\nutm_term=' + utm_term[1] + '\n'; var answer = checkForm($(this).parent().get(0)); if (answer != false) { var $form = $(this).parent(), name = $('input[name="name"]', $form).val(), phone = $('input[name="phone"]', $form).val() + ' ' + $('input[name="phone2"]', $form).val() + ' ' + $('input[name="phone3"]', $form).val(), email = $('input[name="email"]', $form).val(), usluga = $('input[name="usluga"]', $form).val(), referer = $('input[name="referer"]', $form).val(), phrase = $('input[name="phrase"]', $form).val(), ccall = $('input[name="ccall"]', $form).val(), ques = $('textarea[name="ques"]', $form).val(), sbt = $('input[type="button"]', $form).attr("name"), submit = $('input[name=' + sbt + ']', $form).val(); var ref = $('input[name="referer"]').val(); var ref = ref + '\nutm-метки:' + request_url; var formname = $('input[name="formname"]').val(); $.ajax({ type: "POST", url: url, dataType: "json", data: "name=" + name + "&usluga=" + usluga + "&referer=" + referer + "&phrase=" + phrase + "&ccall=" + ccall + "&phone=" + phone + "&" + sbt + "=" + submit + "&email=" + email + "&ques=" + ques + "&formname=" + formname + "&ref=" + ref }).always(function() { //метрики //ga('send', 'event', ''+sbt, ''+sbt, ''+sbt); thx(); }); } }); 
 <div class="popup" id="question"> <div class="popup_h1">Задать вопрос</div> <div class="popup_h2">Оставьте заявку, и наш специалист <br />ответит на все интересующие вас вопросы</div> <form> <em>Имя</em> <label class="name left required"> <input type="text" name="name" class="input_name" placeholder="Татьяна Иванова"> </label> <br> <em>Телефон</em> <label class="phone2 top"> <input type="text" name="phone" class="input_ph1" placeholder="8" value="8"> </label> <label class="phone top required"> <input type="text" name="phone2" class="input_ph2" placeholder="029"> </label> <label class="phone top required"> <input type="text" name="phone3" class="input_ph3" placeholder="4445544"> </label> <br> <em>Ваш вопрос</em> <textarea name="ques" rows="4" placeholder="ваш вопрос"></textarea> <br> <input id=r3 name="referer" type="hidden" value=""> <input id=n3 name="phrase" type="hidden" value=""> <input name="ccall" type="hidden" value="3"> <input name="question" type="button" class="bttn bttn2 button noselect" value="Задать вопрос"> </form> </div> 

This is the PHP file that I'm trying to write:

  /* Здесь проверяется существование переменных */ if (isset($_POST['name'])) {$name = $_POST['name'];} if (isset($_POST['phone'])) {$phone = $_POST['phone'];} if (isset($_POST['ques'])) {$phone = $_POST['ques'];} /* Сюда впишите свою эл. почту */ $address = "madest4815@gmail.com"; /* А здесь прописывается текст сообщения, \n - перенос строки */ $mes = "Тема: Заказ обратного звонка!\nТелефон: $phone\nВопрос: $ques\nИмя: $name "; /* А эта функция как раз занимается отправкой письма на указанный вами email */ $sub='Заказ'; //сабж $email='Заказ <ОКНА ПВХ>'; // от кого $send = mail ($address,$sub,$mes,"Content-type:text/plain; charset = utf-8\r\nFrom:$email"); ini_set('short_open_tag', 'On'); header('Refresh: 3; URL=index.html'); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta http-equiv="refresh" content="3; url=index.htm"> <title>С вами свяжутся</title> <meta name="generator"> <style type="text/css"> body { background: #22BFF7 url(img/zakaz.jpg) top -70% center no-repeat; } <script type="text/javascript"> setTimeout('location.replace("/index.htm")', 3000); /*Изменить текущий адрес страницы через 3 секунды (3000 миллисекунд)*/ </script> </head> </body> </html> 
  • have you checked the variables phone and ques come to your php file? - HELO WORD
  • @HELOWORD Thank you for your attention. I do not understand, tell me how to do it? - Valery Emelyanov
  • @HELOWORD I didn't understand much what I hid. I need only the fields - Name, Phone and Question. - Valery Emelyanov
  • try to write if (isset ($ _ POST ['name'])) {$ name = $ _POST ['name']; echo $ name;} if (isset ($ _ POST ['phone'])) {$ phone = $ _POST ['phone']; echo $ phone;} if (isset ($ _ POST ['ques'])) {$ phone = $ _POST ['ques']; echo $ phone;} - HELO WORD
  • @HELOWORD That's what gives out - Subject: Order a callback! Phone: undefined Question: Name: Gewrf - Valery Emelyanov

1 answer 1

try to send the form like this

  $('.button').click(function() { var msg = $('#formx').serialize(); $.ajax({ type: 'POST', url: 'res.php', data: msg, success: function(data) { $('.results').html(data); }, error: function(xhr, str){ alert('Возникла ошибка: ' + xhr.responseCode); } }); } 

then check for variables in php

 $name =""; $phone =""; $ques =""; if (isset($_POST['name'])) {$name = $_POST['name']; } if (isset($_POST['phone'])) {$phone = $_POST['phone'];} if (isset($_POST['phone2'])) {$phone.= $_POST['phone2'];} if (isset($_POST['phone3'])) {$phone.= $_POST['phone3'];} if (isset($_POST['ques'])) {$ques = $_POST['ques']; } echo "name = ".$name."phone= ".$phone."ques= ".$ques; 
  • There was no need to edit javascript, it was enough to paste your code into php. Thanks a lot for your help! - Valery Emelyanov