should be sent an application to the mail. This is my first pkhp code, please do not judge strictly, and specifically indicate errors.

index.html

<div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal">&times;</button> <h4 class="modal-title">Оставить заявку</h4> </div> <div class="modal-body"> <form action="order.php" method="post"> <input type="text" name="name" placeholder="Имя"> <input type="text" name="phone" placeholder="Телефон"> <input type="text" name="email" placeholder="Почта"> <input type="text" name="message" placeholder="Сообщение"> <hr> <input type="text" name="utm_source" placeholder="Источник"> <input type="text" name="utm_keyword" placeholder="Ключевое слово"> <input type="text" name="utm_campaign" placeholder="Кампания"> <input type="text" name="utm_sourcersy" placeholder="Площадка"> <input type="text" name="utm_medium" placeholder="Тип рекламы"> <input type="text" name="city" placeholder="Город"> </form> </div> <div class="modal-footer"> <button type="submit" name="send" class="btn btn-default">Отправить</button> </div> </div> 

order.php

 <?php error_reporting(-1); ini_set('display_errors', 'On'); date_default_timezone_set(«UTC»); // $to = "89191020010@mail.ru, mirus@mirusdesk.kz"; $to = "zh.zhanelya@gmail.ru, trip.decode.kz"; $subject = "3Dlevel - Новая заявка"; $message = ' <html> <head> <title>'.$subject.'</title> </head> <body> <h2>'.$subject.'</h2> if($_POST["send"]==true){ <p>Имя: ' . $_POST['name'] . '</p> <p>Телефон: ' . $_POST['phone'] . '</p> <p>Почта: ' . $_POST['email'] . '</p> <p>' . $_POST['message'] . '</p> <hr> <p>Источник: ' . $_POST['utm_source'] . '</p> <p>Ключевое слово: ' . $_POST['utm_keyword'] . '</p> <p>Кампания: ' . $_POST['utm_campaign'] . '</p> <p>Площадка: ' . $_POST['utm_sourcersy'] . '</p> <p>Тип рекл.: ' . $_POST['utm_medium'] . '</p> <p>Город: ' . $_POST['city'] . '</p> } </body> </html>'; $headers = "Content-type: text/html; charset=utf-8 \r\n"; $headers .= 'To: zh.zhanelya@gmail.com <zh.zhanelya@gmail.com>' . "\r\n"; // $headers .= 'To: saparjumabekov@gmail.com <saparjumabekov@gmail.com>' . "\r\n"; $headers .= "From: Baby-Club <lead@baby-club.tk>\r\n"; if (mail($to, $subject, $message, $headers)){ echo "da"; } else{ echo "net"; } 
  • <h2> '. $ subject.' </ h2> did not close the quote - Dizzy221
  • offtopic: It is better to send messages using a ready-made library, for example swiftmailer - Vladislav
  • @ Vladislav No, not better, but easier. In order not to create excess weight on a project, it is better to use standard functions (not always of course) - Denis Lazarev
  • @DenisLazarev is in my opinion both better and simpler. Such libraries are not that energy-intensive, and using them leaves the code clean and readable. Especially if you need to change the data for SSL or TLS all the time in the project, and the places where you need to change everything in the project are many (contact, notifications, newsletter, etc.). - Vladislav
  • @ Vladislav It’s just possible to rebuild this code by breaking it up into methods and it will already be visually readable. But if possible, it is better to get rid of those libraries that can be discarded. No offense))) this is my personal opinion - Denis Lazarev

1 answer 1

The variable $ message php code will not be executed.

FIRST, check for the presence of $ _POST ['send']. And then immediately generate $ message without unnecessary conditions. Approximately the code will look like this.

 <php if($_POST['send']){ $message = "здесь сообщение, которое вам нужно выслать"; и здесь же производите отправку сообщения. В вашем примере отправка будет происходить во время каждого запуска файла. А этого, думаю, делать не стоит. header(Location: возвращаемся на страницу); } >