Google Re-Captcha正在运行,但php表单尚未提交

时间:2017-05-08 02:56:07

标签: php html forms

我正在我的html联系页面中创建一个php表单。谷歌重新验证码正在运行,但我的信息没有提交。我不知道问题是什么。这是我的代码。首先是我的HTML代码。

contact.html

为了简洁,我减少了代码

这是放在我头部标签的底部。

我正在使用Go Daddy托管,而stackoverflow建议从网址中删除https

<form action="form.php" method="POST" role="form">
    <div class="form-group">
      <input type="text" name="name" class="form-control" placeholder="Your name">
    </div>

    <div class="form-group">
      <input type="email" name="email" class="form-control" placeholder="Your email">
    </div>

    <div class="form-group">
      <input type="phone" name="phone" class="form-control" placeholder="Your phone number (Optional)">
    </div>

<div class="g-recaptcha" data-sitekey="My Site Key"></div>
  <input type="submit" value="Submit" class="btn btn-success contact-button">
</form>  

这是我的php脚本

 <?php
    if(isset($_POST['submit']) && !empty($_POST['submit'])):
      if(isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])):
      //key
      $secret = 'My 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):
//Section above is for working with the recaptcha
        //contact form submission code


      $name = !empty($_POST['name'])?$_POST['name']:'';
      $email =!empty($_POST['email'])?$_POST['email']:'';
      $phone =!empty($_POST['phone'])?$_POST['phone']:'';
      $occupation =!empty($_POST['occupation'])?$_POST['occupation']:'';
      $option =!empty($_POST['option_group'])?$_POST['option_group']:'';
      $message =!empty($_POST['message'])?$_POST['message']:'';

      $recipient = "ryanbent01@gmail.com";
      $subject = "Potential Digital Delivery Customer";
      $formcontent=" From: $name \n Phone: $phone \n Occupation: $occupation \n Option: $option \n Message: $message";

      $mailheader = "From: $email \r\n";
      //send email
      mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");

      $succMsg = 'Your contact request have submitted successfully.';
    else:
      $errMsg = 'Robot verification failed, please try again.';
    endif;
    else:
      $errMsg = 'Please click on the reCAPTCHA box.';
    endif;
    else:
      $errMsg = '';
      $succMsg = '';
    endif;
    ?>

我甚至没有收到错误消息。

0 个答案:

没有答案