Answer the question
In order to leave comments, you need to log in
Captcha not working, what's wrong with the code?
As a result, it turns out that the captcha was not passed, what could be the error in the code?
Library from here
require_once __DIR__ . '/recaptchalib.php';
$secret = "сюда ввожу свой секретный ключ";
$response = null;
$reCaptcha = new ReCaptcha($secret);
if ($_POST["g-recaptcha-response"]) {
$response = $reCaptcha->verifyResponse(
$_SERVER["REMOTE_ADDR"],
$_POST["g-recaptcha-response"]
);
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST['name']) && (empty($_POST['vopros']) || empty($_POST['phone']))){
echo '<p class="fail">Ошибка. Вы заполнили не все обязательные поля!</p>';
} else {
if ($response != null && $response->success) {
if (isset($_POST['name'])) {
$uname = strip_tags($_POST['name']);
$unameFieldset = "<b>Имя пославшего:</b>";
}
if (isset($_POST['vopros'])) {
$vopros = strip_tags($_POST['vopros']);
$uemailFieldset = "<b>Комментарий:</b>";
}
if (isset($_POST['phone'])) {
$phone = strip_tags($_POST['phone']);
$uphoneFieldset = "<b>Телефон:</b>";
}
$to = "почта";
$sendfrom = "почта";
$headers = "From: " . strip_tags($sendfrom) . "\r\n";
$headers .= "Reply-To: ". strip_tags($sendfrom) . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html;charset=utf-8 \r\n";
$headers .= "Content-Transfer-Encoding: 8bit \r\n";
$message = "$unameFieldset $name<br>
$uemailFieldset $vopros<br>
$uphoneFieldset $phone";
$send = mail ($to, $message, $headers);
if ($send == 'true') {
echo '<p class="success">Спасибо за отправку вашего сообщения!</p>';
} else {
echo '<p class="fail"><b>Ошибка. Сообщение не отправлено!</b></p>';
}
} else {
echo '<p class="success">Не пройдена капча! Попробуйте еще раз!</p>';
}
}
} else {
header ("Location: http://site.ru");
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question