Answer the question
In order to leave comments, you need to log in
Recapcha - how to tie?
Give someone an example of a working form with sending some fields to the mail with a captcha or help to shove
it
here
. ok
, but from the server side, where to shove
anything does not work, where I didn’t tulil
at all, I don’t understand
Help
, you can take a handler, for example. this
<?php
<?php
//Если форма отправлена
if(isset($_POST['submit'])) {
//Проверка Поля ИМЯ
if(trim($_POST['contactname']) == '') {
$hasError = true;
} else {
$name = trim($_POST['contactname']);
}
//Проверка поля ТЕМА
if(trim($_POST['subject']) == '') {
$hasError = true;
} else {
$subject = trim($_POST['subject']);
}
//Проверка правильности ввода EMAIL
if(trim($_POST['email']) == '') {
$hasError = true;
} else if (!eregi("^[A-Z0-9._%-][email protected][A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) {
$hasError = true;
} else {
$email = trim($_POST['email']);
}
//Проверка наличия ТЕКСТА сообщения
if(trim($_POST['message']) == '') {
$hasError = true;
} else {
if(function_exists('stripslashes')) {
$comments = stripslashes(trim($_POST['message']));
} else {
$comments = trim($_POST['message']);
}
}
//Если ошибок нет, отправить email
if(!isset($hasError)) {
$emailTo = '[email protected]'; //Сюда введите Ваш email
$body = "Name: $name \n\nEmail: $email \n\nSubject: $subject \n\nComments:\n $comments";
$headers = 'From: My Site <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
mail($emailTo, $subject, $body, $headers);
$emailSent = true;
}
}
?>
Answer the question
In order to leave comments, you need to log in
Paste this into your form
<div class="g-recaptcha" data-sitekey="SITEKEY" id="captcha"></div>
$url1 = 'https://www.google.com/recaptcha/api/siteverify?secret=SECRET&response='.(array_key_exists('g-recaptcha-response', $data) ? $data["g-recaptcha-response"] : '').'&remoteip='.$_SERVER['REMOTE_ADDR'];
$resp1 = json_decode(file_get_contents($url1), true);
if ($resp1['success'] != true) {
// Тут код, который срабатывает в случае ошибки
// Пример: $errors[] = 'Не правильно решена каптча';
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question