如何使用Recaptcha开始php联系表单?

时间:2019-04-17 14:11:44

标签: php html recaptcha contact-form

我创建了一个与PHPMailer完美配合的联系表。但是,我开始从机器人那里收到很多垃圾邮件。我每天大约收到50。因此,我尝试通过观看此视频YouTube来实现Google Recaptcha。现在,我从Google表单0-1.0收到分数,但是我的联系表单不再起作用。如何实现Recaptcha,以便它决定是否发送电子邮件?

  <div class="form-group">
                 <form method="POST" action="/" enctype="multipart/form-data">
                 <input class="form-control" name="name" placeholder="Namn" required ><br>
                 <input class="form-control" name="phone" placeholder="Telefonnummer" required ><br>
                 <input class="form-control" name="email" type="email" placeholder="E-post" required ><br>
                 <input class="form-control" name="company" placeholder="Företag/Organisation" required ><br>
                 <input type="hidden" id="g-recaptha-response" name="g-recaptha-response">
                 <input class="btn btn-primary" id="register-btn" name="submit" type="submit" value="Skicka e-post">
               </form>
               <script src="https://www.google.com/recaptcha/api.js?render=reCAPTCHA_site_key"></script>
                <script>
                grecaptcha.ready(function() {
                grecaptcha.execute('6LduT4MUAAAAAAtMBYDonU53LDKm9BTBZas6kfnT', {action: 'homepage'})
                .then(function(token) {
                   //console.log(token);
                   document.getElementById('g-recaptha-response').value=token;
                   });
                   });
                   </script>
            </div>
          </div>



  $Return =getCaptcha($_POST['g-recaptha-response']);
  //var_dump($Return);
  if($Return->success == true && $Return->score > 0.5 ){
    echo "Succes!";
  }else{
    echo "You're a robot!";
  }
}

我想在if($ Return-> success == true的情况下运行PHP电子邮件程序 如果可能的话。有可能吗?

0 个答案:

没有答案