Greetings The site has 5 different forms. The script saves the variable data from the fields (name, mail, phone) and sends them to my mail. It is necessary to make it so that, in addition to all the information that users of the site will enter, the content of the letter indicated the name of the form with which the message was sent. How can this be realized?

<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Обратная связь</title> <meta http-equiv="Refresh" content="4; URL=http://"> </head> <body> <?php $sendto = "@gmail.com"; $username = $_POST['name']; $usertel = $_POST['telephone']; $usermail = $_POST['email']; $usluga = $_POST['usl']; // Формирование заголовка письма $subject = "Новое сообщение"; $headers = "From: " . strip_tags($usermail) . "\r\n"; $headers .= "Reply-To: ". strip_tags($usermail) . "\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: text/html;charset=utf-8 \r\n"; // Формирование тела письма $msg = "<html><body style='font-family:Arial,sans-serif;'>"; $msg .= "<h2 style='font-weight:bold;border-bottom:1px dotted #ccc;'>Cообщение с сайта</h2>\r\n"; $msg .= "<p><strong>От кого:</strong> ".$username."</p>\r\n"; $msg .= "<p><strong>Почта:</strong> ".$usermail."</p>\r\n"; $msg .= "<p><strong>Телефон:</strong> ".$usertel."</p>\r\n"; $msg .= "</body></html>"; // отправка сообщения if(@mail($sendto, $subject, $msg, $headers)) { echo "<center><img src='images/spasibo.png'></center>"; } else { echo "<center><img src='images/ne-otpravleno.png'></center>"; } ?> </body> </html> 

3 answers 3

 <form name="название_формы"> // не видно для пользователя <input type="hidden" name="form-name" value="название_формы" /> </form> 

    To the previous answer I add that in the server handler you need to add

     // Формирование тела письма $msg = "<html><body style='font-family:Arial,sans-serif;'>"; $msg .= "<h2 style='font-weight:bold;border-bottom:1px dotted #ccc;'>Cообщение с сайта</h2>\r\n"; $msg .= "<p><strong>От кого:</strong> ".$username."</p>\r\n"; $msg .= "<p><strong>Почта:</strong> ".$usermail."</p>\r\n"; $msg .= "<p><strong>Телефон:</strong> ".$usertel."</p>\r\n"; // Добавить эту строку $msg .= "<p><strong>Форма:</strong> ".$_REQUEST['form-name']."</p>\r\n"; $msg .= "</body></html>"; 

      I do not see why this is a problem? It is enough to add to the message being formed, to the code block with the concatenation of the $ msg variable, the addition of the type "Clothing order form" or "Footwear order form" or whatever you need. For example:

       $msg .= "<p>Отправлено формой заказа раздела <strong>Одежда</strong></p>\r\n"; 

      And what would have been more convenient, you can directly in the subject line of the letter indicate from which form the message came. Then you need to change the string with the variable $ subject. For example:

       $subject = "Новое сообщение, форма раздела Фурнитура";