There is a PHP script (application form on the site) when I click send ?, the page from the main page goes to http // site123 / form1.php in an empty window. Question: How to make sure that after submitting the form, there was a return to the main popup window (it is already written in html) “Thank you for the application”?

<?php // несколько получателей $to = 'culik.dima2017@yandex.ru' . ', '; // обратите внимание на запятую $to .= 'wez@example.com'; // тема письма $subject = 'Письмо с моего сайта'; // текст письма $message = 'Пользователь' . $_POST['name'] . ' отправил вам письмо:<br />' . $_POST['message'] . '<br /> Связяться с ним можно по phone11 <a href="mailto:' . $_POST['phone11'] . '">' . $_POST['phone11'] . '</a>' ; // Для отправки HTML-письма должен быть установлен заголовок Content-type $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Дополнительные заголовки $headers .= 'To: Иван <Ivan@example.com>' . "\r\n"; // Свое имя и phone11 $headers .= 'From: ' . $_POST['name'] . '<' . $_POST['phone11'] . '>' . "\r\n"; // Отправляем mail($to, $subject, $message, $headers); ?> 
  • Use AJAX for this purpose, send data to the required handler, and in case of failure / success, call the popup with the necessary message - DaemonHK
  • Possible duplicate question: Automatic form submission without page reload - Alex

1 answer 1

 function send_post(url, data){ var xhr = new XMLHttpRequest(); xhr.open('POST', url, true); xhr.setRequestHeader('Content-Type', 'multipart/form-data; boundary=' + boundary); xhr.onreadystatechange = function() { if (this.readyState != 4) return; //Тут отправляем "Спасибо за Вашу заявку!" } xhr.send(data); } var data = "name=name&message=message&phone11=phone11и.т.д"; var url = "http//сайт123/form1.php"; send_post(url, data); 
  • Your code does not work: <? Php function send_post (url, data) {var xhr = new XMLHttpRequest (); xhr.open ('POST', url, true); xhr.setRequestHeader ('Content-Type', 'multipart / form-data; boundary =' + boundary); xhr.onreadystatechange = function () {if (this.readyState! = 4) return; // Here we send "Thank you for your application!" } xhr.send (data); } var data = "name = name & message = message & phone11 = phone11i.t.d"; var url = "http // my-puff.ru / form1.php"; send_post (url, data); ?> - Dima
  • What does the console issue? - Andrey Bespalov
  • goes to my-puff.ru/form1.php , the page is unavailable The site my-puff.ru cannot process this request yet. HTTP ERROR 500 - Dima
  • Well, there is an error in the php script itself, and not in the code I wrote. Variable data as you look like? - Andrei Bespalov
  • I don't really understand php, what should be in place of data? - Dima