Всем привет. Помогите с формой заявки на html + php. Я в php почти не разбираюсь... Есть форма:
<form action="mail.php" method="POST" class="th-contact-form ajax-contact" data-bg-src="<?php bloginfo('template_directory'); ?>/img/bg/feature-bg1.png">
<div class="form-title">
<h3 class="page-subtitle h4 mb-30 mt-n1">Оставьте заявку</h3>
</div>
<div class="row">
<div class="col-xl-6 form-group">
<input type="text" placeholder="Имя" class="form-control style2">
</div>
<div class="col-xl-6 form-group">
<input type="text" placeholder="Email Address" class="form-control style2">
</div>
<div class="col-md-12 form-group">
<input type="text" placeholder="Регион" class="form-control style2">
</div>
<div class="col-12 form-group">
<textarea placeholder="Сообщение" class="form-control style2"></textarea>
</div>
<div class="col-12 form-group mb-0">
<input type="submit" class="th-btn fas fa-arrow-right ms-2">
</div>
</div>
</form>
И обработчик на php:
// Only process POST reqeusts.
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Get the form fields and remove whitespace.
$name = strip_tags(trim($_POST["name"]));
$name = str_replace(array("\r","\n"),array(" "," "),$name);
$email = filter_var(trim($_POST["email"]), FILTER_SANITIZE_EMAIL);
$subject = trim($_POST["subject"]);
$number = trim($_POST["number"]);
$message = trim($_POST["message"]);
// Check that data was sent to the mailer.
if ( empty($name) OR empty($message) OR empty($number) OR empty($subject) OR !filter_var($email, FILTER_VALIDATE_EMAIL)) {
// Set a 400 (bad request) response code and exit.
http_response_code(400);
echo "Пожалуйста отправьте форму повторно";
exit;
}
// Set the recipient email address.
// FIXME: Update this to your desired email address.
$recipient = "mail@key-word.ru";
// Set the email subject.
$subject = "New contact from $subject";
// Build the email content.
$email_content = "Name: $name\n";
$email_content .= "Subject: $subject\n";
$email_content .= "Email: $email\n\n";
$email_content .= "Message:\n$message\n";
// Build the email headers.
$email_headers = "From: $name <$email>";
// Send the email.
if (mail($recipient, $subject, $email_content, $email_headers)) {
// Set a 200 (okay) response code.
http_response_code(200);
echo "Спасибо за вашу заявку!";
} else {
// Set a 500 (internal server error) response code.
http_response_code(500);
echo "Что-то не так, пожалуйста отправьте заявку повторно.";
}
} else {
// Not a POST request, set a 403 (forbidden) response code.
http_response_code(403);
echo "There was a problem with your submission, please try again.";
}
?>
После отправки формы ничего не происходит... Может кто знает как заставить форму работать? P/S: сайт лежит на боевом хостинге.