简体   繁体   中英

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 .

before google captcha working my code properly but now nothing working.

thanks

You need to handle the Captcha inside email.php. Before getting other posted field values you can check for Capcha response. Also don't forget that you need to post the captcha field (g-recaptcha-response) value like you post name, phone, email and messsage.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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