Hello guys! When submitting an application, the browser goes to an empty php file containing the form submission script, with this form working but I would like a window to pop up about successful submission or at least just the page is updated. Thank you very much in advance!

<div class="popup reg_form"> <a class="close" href="#">&times;</a> <h2>ОТПРАВИТЬ ЗАЯВКУ</h2> <form id="contactForm" class="contact-form" method="post" action="contact_mailer.php"> <div class="form-group form-icon-group"> <input class="form-control" name="name" id="name" placeholder="Ваше Имя*" type="text" required> <i class="fa fa-user"></i> </div> <div class="form-group form-icon-group"> <input class="form-control" name="email" placeholder="Ваш e-mail*" type="email" required> <i class="fa fa-envelope"></i> </div> <div class="form-group form-icon-group"> <input class="form-control" name="phone" placeholder="Контактный телефон*" type="text" required> <i class="fa fa-phone"></i> </div> <div> <input type="submit" value="Отправить заявку" class="btn btn-danger scroll-to-id "> </div> </form> <?php if((isset($_POST['name'])&&$_POST['name']!="")&&(isset($_POST['email'])&&$_POST['email']!="")&&(isset($_POST['phone'])&&$_POST['phone']!="")){ $to = 'godofwar9325@gmail.com'; //Почта получателя, через запятую можно указать сколько угодно адресов $subject = 'Обратный звонок'; //Загаловок сообщения $message = ' <html> <head> <title>'.$subject.'</title> </head> <body> <p><b>Имя:</b> '.$_POST['name'].'</p> <p><b>Телефон:</b> '.$_POST['phone'].'</p> <p><b>Почта:</b> '.$_POST['email'].'</p> </body> </html>'; //Текст нащего сообщения можно использовать HTML теги $headers = "Content-type: text/html; charset=utf-8 \r\n"; //Кодировка письма $headers .= "From: Отправитель <uber-key.ru>\r\n"; //Наименование и почта отправителя mail($to, $subject, $message, $headers); //Отправка письма с помощью функции mail }?> <?php if((isset($_POST['name'])&&$_POST['name']!="")&&(isset($_POST['email'])&&$_POST['email']!="")&&(isset($_POST['phone'])&&$_POST['phone']!="")){ $to = 'godofwar9325@gmail.com'; //Почта получателя, через запятую можно указать сколько угодно адресов $subject = 'Обратный звонок'; //Загаловок сообщения $message = ' <html> <head> <title>'.$subject.'</title> </head> <body> <p><b>Имя:</b> '.$_POST['name'].'</p> <p><b>Телефон:</b> '.$_POST['phone'].'</p> <p><b>Почта:</b> '.$_POST['email'].'</p> </body> </html>'; //Текст нащего сообщения можно использовать HTML теги $headers = "Content-type: text/html; charset=utf-8 \r\n"; //Кодировка письма $headers .= "From: Отправитель <uber-key.ru>\r\n"; //Наименование и почта отправителя mail($to, $subject, $message, $headers); if(mail(@params)){ //та самая проверка ответа mail(); из коммента header('Location: uber-key.ru/index.html'); }else{ header('Location: uber-key.ru/failed.html'); } index.html echo 'main send successfully'; failed.html echo 'main didnt send becouse of ...'; }?> 

    2 answers 2

    After the mail($to, $subject, $message,...... line mail($to, $subject, $message,...... Add echo "<h2>Заявка отправлена</h2>";

    • Thank you very much, everything turned out. - Anton Rodionov
    • Can I do something to make the browser return to the main page after echo? - Anton Rodionov
    • and if the application is not sent? no check. at least if () - Kirill Korushkin
    • Cyril can be more? - Anton Rodionov
    • There is still one caveat, the inscription on apple devices is displayed with krakozabrami, how can I fix it? - Anton Rodionov

    In your case there are several ways to solve the problem.

    The first and most obvious (but not the best) is to redirect the user after sending a letter to the page of a message about successful or unsuccessful sending. This is usually implemented as follows:

     if(mail(@params)){ //та самая проверка ответа mail(); из коммента header('Location: http://yoursite.com/success.html'); }else{ header('Location: http://yoursite.com/failed.html'); } success.html echo 'main send successfully'; failed.html echo 'main didn't send becouse of ...'; 

    You can also return to the original page (where you filled out the form) with a get-to-send letter marker:

     if(mail(@params)){ header('Location: http://where_you_came_from.com?m=1'); } 

    Then in the source file you will check $ _get:

     if($_get && isset($_get['m'])){ echo ($_get['m']) ? 'блок с сообщением об отправке письма' : 'блок с сообщением об ошибке отправки'. } 

    This method can redirect the user to any page, depending on your needs. And about the output of messages in the handler file just forget, as you learn the language and programming patterns, everything will fall into place until you just remember (IMHO).

    The second processing method is ajax , this is js. I highly recommend studying.

    Separately, I want to draw your attention to the processing of data coming from the forms. In your example, you send the data to the function without processing. In the case of a letter, this is not so important, but when in the future you start working with the database, this will be unforgivable.

    • Thank you very much for the answer! I tried the first method but for some reason it didn’t come out, the code was inserted in vporos - Anton Rodionov
    • header send through the absolute link header ('Location: http (s): //uber-key.ru/index.html'); - Kirill Korushkin