谷歌重新验证不能在现有的PHP表单中工作

时间:2018-06-05 00:09:54

标签: php recaptcha

请耐心等待,我是新来的。 :)我似乎无法让Google重新验证码在我现有的PHP表单中工作 - 见下文。我确定我需要删除或添加代码。此外,我希望在提交到我的电子邮件之前验证重新验证码。非常感谢。

<?php

if(isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])):

    $secret = 'secret key';
    //get verify response data
    $verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secret.'&response='.$_POST['g-recaptcha-response']);
    $responseData = json_decode($verifyResponse);
    if($responseData->success):


//redirect if login was successful
header('Location: ./xxxx.hmtl');

$myemail = 'email@hotmail.com';
if (isset($_POST['email'])) {
$subject = $_POST['subject'];
$email = $_POST['email'];
$message = $_POST['message'];
echo "Email:".$email."<br>";
echo "Subject:".$subject."<br>";
echo "Message:".$message."<br>";

if ($_POST['subject'] ) { 
echo 'Tastes Like Spam!'; }
else {
$success = true; mail($myemail);

}

$to = $myemail;
$email_subject = "xxxx.com New Message: $subject";
$email_body = "You have received a new message. ".
" Details are below:\n Subject: $subject \n ".
"Email: $email\n Message: \n $message";
$headers = "From: $myemail\n";
$headers .= "Reply-To: $email";
mail($to,$email_subject,$email_body,$headers);

}

&GT;

我的html表单代码如下。我不确定为什么它不会重定向到主页也不提交表单。它会转到错误页面 - 基本上是.php网址。感谢您的帮助和耐心:)

    <div class="section-container-spacer">
        <form action="process.php" class="reveal-content" method="post" onsubmit="myFunction()">
          <div class="row">
            <div class="col-md-6">
              <div class="form-group">
                <input type="text" name="email" class="form-control" id="email" placeholder="Email" required="">
              </div>
              <div class="form-group">
                <input type="text" name="subject" class="form-control" id="subject" placeholder="Subject" required="">
              </div>
              <div class="form-group">
                <textarea name="message" class="form-control" rows="3" id="message" placeholder="Enter your message" required=""></textarea>
              </div>
                <div class="form-group"><div class="g-recaptcha" data-sitekey="site key goes here"></div></div>
              <button type="submit" class="btn btn-primary btn-lg">Send</button>
            </div>
            <div class="col-md-6">
              <ul class="list-unstyled address-container">
                <li> <span class="fa-icon"> <i class="fa fa-at" aria-hidden="true"></i> </span> <a href="mailto:email@.hotmail.com">email@hotmail.com</a> </li>
                <li> <span class="fa-icon"> <i class="fa fa fa-map-marker" aria-hidden="true"></i> </span> Los Angeles, CA </li>
              </ul>
            </div>
          </div>
        </form>
        <script>
function myFunction() {
    alert("Your message has been sent. We will be in touch.");
}
</script> 
        <script type="text/javascript">
     $(document).ready(function () {
$("input#submit").click(function(){
    $.ajax({
        type: "POST",
        url: "process.php",
        data: $('form.contact').serialize(),
        success: function(msg){
            $("#thanks").html(msg) 
        },
        error: function(){
            alert("failure");
        }
    });
});
});
  </script> 
      </div>

0 个答案:

没有答案