I
I
i_m2020-06-03 19:07:15
PHP
i_m, 2020-06-03 19:07:15

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

1 answer(s)
N
noob noob, 2020-06-03
@YashaWeb

Paste this into your form

<div class="g-recaptcha" data-sitekey="SITEKEY" id="captcha"></div>

This is PHP server side validation
$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[] = 'Не правильно решена каптча';
            }

Take SITEKEY and SECRET in your recapthca account5ed7d572d320f184515681.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question