There is such html code:

<html> <head> <meta charset="utf-8"> <title>Test</title> <link rel="stylesheet" href="style.css"> </head> <body> <div class="backgr"> <br><br><br><br><br><br><br> <h2 class=text align="center"> Оставьте заявку </h2> <form name="test" method="post" action="sendform.php" align="center"> <div> <input type="text" class="brd" placeholder="Имя" name="first_name"> </div> <div> <input type="text" class="brd" placeholder="Телефон" name="phone_number"> </div> <div> <input type="text" class="brd" placeholder="E-mail" name="client_mail"> </div> <br> <div> <button type="submit" form="test" name="sended" class="button">Отправить форму</button> </div> </form> <br><br><br><br><br><br><br><br><br><br> </div> </body> </html> 

The php file to submit the form looks like this:

 <?php function died($error) { die(); } if(!isset($_POST['sended'])) { died("Йуху"); } $first_name = $_POST['first_name']; $phone_number = $_POST['phone_number']; $client_mail = $_POST['client_mail']; $email1="leshaber24@yandex.ru"; $email_message = str_replace("#USER_NAME#", $first_name, file_get_contents("./emailinfo.html")); $email_message = str_replace("#PHONE_NUMBER#", $phone_number, file_get_contents("./emailinfo.html")); $email_message = str_replace("#CLIENT_MAIL#", $client_mail, file_get_contents("./emailinfo.html")); $headers = 'From: '.$email1."\r\n". 'Reply-To:'.$email1."\r\n" . 'X-Mailer: PHP/' . phpversion(); $headers .= 'MIME-Version: 1.0'."\r\n"; $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n"; mail($email1, "Тестовое задание", $email_message, $headers); ?> <meta charset="utf-8"> <h1 class="animated shake">Спасибо, с вами скоро свяжутся!</h1> 

And the letter itself, which should come in the mail:

 <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Письмо с сайта</title> <style type="text/css"> <p style="font-family:sans-serif;font-size:14px;font-weight:normal;margin:0;Margin-bottom:15px;">Привет, меня зовут: <span>#USER_NAME#</span> </p> <p style="font-family:sans-serif;font-size:14px;font-weight:normal;margin:0;Margin-bottom:15px;">Мой номер: <span>#PHONE_NUMBER#</span> </p> <p style="font-family:sans-serif;font-size:14px;font-weight:normal;margin:0;Margin-bottom:15px;">Моя почта: <span>#CLIENT_MAIL#</span> </p> </body> </html> 

The button to send is not clicked on the site and, accordingly, the php code is not executed. Thank!

  • How not to push? Is there an example? Where can I see - Farkhod Daniyarov
  • On abereznyak.ru this whole example is lesha_ber

1 answer 1

Error number 1.

 <button type="submit" form="test" name="sended" class="button">Отправить форму</button> 

Attribute form="test" clean should work. When HTML looks weird, roll the markup over https://validator.w3.org/

Error number 2.

 $email_message = str_replace("#USER_NAME#", $first_name, file_get_contents("./emailinfo.html")); $email_message = str_replace("#PHONE_NUMBER#", $phone_number, file_get_contents("./emailinfo.html")); $email_message = str_replace("#CLIENT_MAIL#", $client_mail, file_get_contents("./emailinfo.html")); 

You need to read "./emailinfo.html"

 $html = file_get_contents("./emailinfo.html"); // Массивы с заменой $search = array("#USER_NAME#", "#PHONE_NUMBER#", "#CLIENT_MAIL#"); $replace = array($first_name, $phone_number, $client_mail); $email_message = str_replace($search, $replace, $html); 
  • instead of seeing the error, why in the letter that I receive, only the e-mail is substituted, and the first two fields are not, which are also described under str_replace? - lesha_ber
  • @lesha_ber Please mark the answer as accepted if it has solved your question (green check mark to the left of the answer). - Vadim Ovchinnikov