Форма обратной связи на Bootstrap4
Простая форма обратной связи, поля:
- Имя (обязательное)
- Телефон (обязательное)
- Субъект
- Сообщение
- Кнопка Отправить
HTML код формы
<form id="feedbackForm" method="post" action="/send_form.php" accept-charset="UTF-8">
<!-- Your form fields here -->
<input type="text" placeholder="Name" class="form-control" id="name" name="name" required>
<input type="tel" placeholder="Phone" class="form-control" id="phone" name="phone" required>
<input type="text" placeholder="Subject" class="form-control" id="subject" name="subject" required>
<textarea class="form-control" placeholder="Message" id="message" name="message" rows="5" required></textarea>
<button type="submit" class="btn btn-lb">SEND</button>
</form>
Как видно из кода, к нему нужно подключить send_form.php, вот его код
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = htmlspecialchars($_POST["name"]);
$phone = htmlspecialchars($_POST["phone"]);
$subject = htmlspecialchars($_POST["subject"]);
$message_content = htmlspecialchars($_POST["message"]);
$to = "[email protected]";
$headers = "From: $name <$to>\r\n";
$headers .= "Content-type: text/html; charset=utf-8\r\n";
$headers .= "Subject: Заказ с сайта\r\n"; // Добавленный заголовок
$message = "Name: $name<br>";
$message .= "Phone: $phone<br>";
$message .= "Subject: $subject<br>";
$message .= "Message: $message_content<br>";
if (mail($to, $subject, $message, $headers)) {
$status = "success";
$message = "Form submission successful!";
} else {
$status = "error";
$message = "Form submission failed. Please try again.";
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Form Submission</title>
</head>
<body>
<?php if (isset($status)): ?>
<div class="<?php echo $status; ?>"><?php echo $message; ?></div>
<?php endif; ?>
</body>
</html>
А вот форма с селектами для поля subject