简体   繁体   English

邮件功能不适用于Google验证码

[英]mail function not working with google captcha

 <div class="row"> <div class="col-xs-12 col-lg-10 col-lg-offset-1"> <form method="post" action="" name="contactForm" id="contactform" class="clearfix"> <fieldset> <div class="float-left"> <div class="coolfx fadeInUp"> <!--<span>*Name<label for="name"></label></span>--> <span><input type="text" id="contactName" name="name" placeholder="*Name" class="text" required></span> </div> <div class="coolfx fadeInUp" > <!--<span>*Email<label for="email"></label></span>--> <span><input type="email" id="contactEmail" name="email" placeholder="*Email" class="email" required></span> </div> <div class="coolfx fadeInUp"> <!--<span>Phone<label for="phone"></label></span>--> <span><input type="text" id="contactPhone" name="phonenumber" placeholder="Phone" class="text" required></span> </div> </div> <div class="float-right"> <div class="contactform message coolfx fadeInUp"> <!--<span>Message<label for="message"></label></span>--> <span><textarea id="contactMessage" placeholder="*Message" name="message" class="textarea" required></textarea></span> </div> </div> </fieldset> <div class="float-right"><div class="g-recaptcha" data-sitekey="6LfsPBgTAAAAAPDkaI1HeSyDm_ecF0iihVsFYBKh"></div></div> <div class="coolfx fadeInUp"> <input name="send" type="submit" class="submit" id="submit" value="Send Email"> </div> 

<?php

 if(isset($_POST['g-recaptcha-response']))
      $url = 'https://www.google.com/recaptcha/api/siteverify';
   $privatekey = "******************************";// hide for security
     $response = file_get_contents($url."?secret=".$privatekey."&response=".$_POST['g-recaptcha-response']."&remoteip=".$_SERVER['REMOTE_ADDR']);
 $data = json_decode($response);


 if (isset($data->success) AND $data->success==true) {?>


<script type="text/javascript">
$(function() {
$("#contactform .submit").click(function() {
    var data = {
name: $("#contactName").val(),
email: $("#contactEmail").val(),
 phone: $("#contactPhone").val(),
message: $("#contactMessage").val()
 };
  $.ajax({
   type: "POST",
   url: "email.php",
   data: data,
     success: function(){
    $('.success').fadeIn(1000);
      }
   });
   });
  });
</script>


  <?php  }else {
          echo"this is spam"
    }?>

I am new in j query how to use j query code inside the php code and also how to verify google captcha code before submit a mail function nothing working . 我是j查询的新手,如何在php代码中使用j查询代码,以及如何在提交邮件功能之前验证Google验证码。

before google captcha working my code properly but now nothing working. 之前谷歌验证码正常工作我的代码,但现在没有任何工作。

thanks 谢谢

You need to handle the Captcha inside email.php. 您需要在email.php中处理验证码。 Before getting other posted field values you can check for Capcha response. 在获取其他发布的字段值之前,您可以检查Capcha响应。 Also don't forget that you need to post the captcha field (g-recaptcha-response) value like you post name, phone, email and messsage. 同样不要忘记,您需要像输入姓名,电话,电子邮件和消息一样输入验证码字段(g-recaptcha-response)值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM