A
A
Andrej Sharapov2019-03-07 11:47:45
PHP
Andrej Sharapov, 2019-03-07 11:47:45

How to add spam protection to the feedback form?

Good afternoon developers.
Tell me how to add spam protection to the feedback form? Simple landing, without cms and recaptcha.
Thanks in advance.

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    if (isset($_POST['formData'])) {$formData = $_POST['formData'];}
    if (isset($_POST['email'])) {$email = $_POST['email'];}
    if (isset($_POST['name'])) {$name = $_POST['name'];}
    if (isset($_POST['phone'])) {$phone = $_POST['phone'];}
    if (isset($_POST['message'])) {$message = $_POST['message'];
}
    
$to = почта@mail.ru";    
$headers = "Content-type: text/plain; charset = utf-8";
$subject = "$formData";
$message = "$formData\n\nОткуда: $email \n\nОтправитель: $name \n\nТелефон: $phone \n\nСообщение: $message";
$send = mail ($to, $subject, $message, $headers);
if ($send == 'true') {
    echo "<center>Спасибо за отправку вашего сообщения! Наши специалисты свяжутся с вами в течение часа.</center>";
} else {
    echo "<center><b>Ошибка. Сообщение не отправлено! Проверьте правильность введенных данных</b></center>";
}
} else {
    http_response_code(403);
    echo "Попробуйте еще раз";
}
?>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Arseniy Togulev, 2019-03-07
@tetra

Related article https://www.lifewire.com/solutions-to-protect-web-...

E
Evgeny Bukharev, 2019-03-07
@evgenybuckharev

Hidden field, on the server we check if it is spam, 95% of bots will be eliminated

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question