reCAPTCHA не может найти предоставленную пользователем функцию: onloadCallback

Когда я загружаю свою страницу, я получаю эту ошибку в консоли

«reCAPTCHA не смог найти предоставленную пользователем функцию: onloadCallback»

Я следовал руководству по phppot для PHP с Google Recaptcha. Когда я нажимаю «Отправить», не выполняя recaptcha, я получаю сообщение об ошибке, в котором говорится, что мне нужно завершить его.
Однако, когда я это делаю, он показывает мой символ загрузки в бесконечном цикле и фактически не отправляет электронное письмо. У меня есть следующие коды ниже:

    $(document).ready(function (e){
$("#frmContact").on('submit',(function(e){
e.preventDefault();
$("#mail-status").hide();
$('#send-message').hide();
$('#loader-icon').show();
$.ajax({
url: "contact.php",
type: "POST",
dataType:'json',
data: {
"name":$('input[name="name"]').val(),
"email":$('input[name="email"]').val(),
"phone":$('input[name="phone"]').val(),
"content":$('textarea[name="content"]').val(),
"g-recaptcha-response":$('textarea[id="g-recaptcha-response"]').val()},
success: function(response){
$("#mail-status").show();
$('#loader-icon').hide();
if(response.type == "error") {
$('#send-message').show();
$("#mail-status").attr("class","error");
} else if(response.type == "message"){
$('#send-message').hide();
$("#mail-status").attr("class","success");
}
$("#mail-status").html(response.text);
},
error: function(){}
});
}));
});

находится в моем разделе в верхней части моей страницы contactus.php.

Тогда у меня есть следующее для моей страницы contact.php:

 if($_POST)

{

$user_name      = filter_var($_POST["name"], FILTER_SANITIZE_STRING);
$user_email     = filter_var($_POST["email"], FILTER_SANITIZE_EMAIL);
$user_phone     = filter_var($_POST["phone"], FILTER_SANITIZE_STRING);
$content   = filter_var($_POST["content"], FILTER_SANITIZE_STRING);

if(empty($user_name)) {
$empty[] = "<b>Name</b>";
}
if(empty($user_email)) {
$empty[] = "<b>Email</b>";
}
if(empty($user_phone)) {
$empty[] = "<b>Phone Number</b>";
}
if(empty($content)) {
$empty[] = "<b>Comments</b>";
}

if(!empty($empty)) {
$output = json_encode(array('type'=>'error', 'text' => implode(", ",$empty) . ' Required!'));
die($output);
}

if(!filter_var($user_email, FILTER_VALIDATE_EMAIL)){ //email validation
$output = json_encode(array('type'=>'error', 'text' => '<b>'.$user_email.'</b> is an invalid Email, please correct it.'));
die($output);
}

//reCAPTCHA validation
if (isset($_POST['g-recaptcha-response'])) {

require('component/recaptcha/src/autoload.php');

$recaptcha = new \ReCaptcha\ReCaptcha(SECRET_KEY, new \ReCaptcha\RequestMethod\SocketPost());

$resp = $recaptcha->verify($_POST['g-recaptcha-response'], $_SERVER['REMOTE_ADDR']);

if (!$resp->isSuccess()) {
$output = json_encode(array('type'=>'error', 'text' => '<b>Captcha</b> Validation Required!'));
die($output);
}
}

$toEmail = "member@testdomain.com";
$mailHeaders = "From: " . $user_name . "<" . $user_email . ">\r\n";
if (mail($toEmail, "Contact Mail", $content, $mailHeaders)) {
$output = json_encode(array('type'=>'message', 'text' => 'Hi '.$user_name .', thank you for the comments. We will get back to you shortly.'));
die($output);
} else {
$output = json_encode(array('type'=>'error', 'text' => 'Unable to send email, please contact'.SENDER_EMAIL));
die($output);
}

}

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector