谷歌recaptcha和形式不工作

时间:2018-06-06 11:28:57

标签: php forms recaptcha contacts

我试图在我的网站上实施google recaptcha。但由于某种原因,它不起作用。表格没有提交。还有captcha recheck错误无法正常工作。我也插入了我的google recaptcha密钥。

我从互联网上找到了验证码验证码 我做错了什么?

<?php


if ( isset( $_POST[ 'g-recaptcha-response' ] ) && $_POST[ 'g-recaptcha-response' ] ) {
    var_dump( $_POST );
    $secret = "my secret key";
    $ip = $_SERVER[ 'REMOTE_ADDR' ];
    $captcha = $_POST[ 'g-recaptcha-response' ];
    $rsp = file_get_contents( "https://www.google.com/recaptcha/api/siteverify?secret=$secret&response=$captcha&remoteip$ip" );
    var_dump( $rsp );
    $arr = json_decode( $rsp, TRUE );

    if ( $arr[ 'success' ] ) {


        $address = "myemail@yahoo.com";


        $CompanyName = $_POST[ 'CompanyName' ];
        $ContactName = $_POST[ 'ContactName' ];
        $City = $_POST[ 'City' ];
        $State = $_POST[ 'State' ];
        $Phone = $_POST[ 'Phone' ];
        $Email = $_POST[ 'Email' ];
        $FromFind = $_POST[ 'FromFind' ];
        $Comments = $_POST[ 'Comments' ];
        $Page = $_POST[ 'Page' ];

        $headers = "From: $Email";
        $headers .= "Reply-To: $Email";
        $headers .= "MIME-Version: 1.0";
        $headers .= "Content-type: text/plain; charset=utf-8";
        $headers .= "Content-Transfer-Encoding: quoted-printable";

        $e_subject = 'MicroShred.com Form Contact by ' . $ContactName . '.';
        // Email message:
        $msg = "You have been contacted by $ContactName, in $City $State, through your $Page. Their message is as follows:";
        $msg .= "$Comments";
        $msg .= "You can contact $ContactName via email, $Email or via phone $Phone.";
        $msg .= "-------------------------------------------------------------------------------------------";
        $msg .= "This message was sent to you via your website Contact Form";
        $msg = wordwrap( $msg, 70 );

        if ( mail( $address, $e_subject, $msg, $headers ) ) {

            echo "<fieldset>";
            echo "<div class=\"notification success closeable\">";
            echo "<p><strong>Email Sent Successfully.</strong><br />";
            echo "Thank you $name, your message has been submitted to us.</p>";
            echo "</div>";
            echo "</fieldset>";

        } else {

            echo 'ERROR!';

        }




    } else {
        echo ' please make sure that you have checked the captcha';
    }


}


?>

这是表格

  <form method="post" action="/_contact-form/contact2.php" name="contactform" id="contactform" onSubmit="return validate_form();">
            <input type="hidden" name="mode" value="Send" />
            <input type="hidden" name="Page" value="Scheduled Shredding Services Page" />
            <input type="hidden" name="path" value="/shredding-services-florida/scheduled-visits.php" />
            <table width="60%" border="0" align="right" cellpadding="3" cellspacing="3" class="text">
              <tr>
                <td colspan="3" class="main"></td>
              </tr>
              <tr align="center" valign="middle">
                <td class="main"><div align="center"><strong>Company Name</strong></div></td>
                <td colspan="2"><input type="text" id="CompanyName" name="CompanyName" size="30" /></td>
              </tr>
              <tr align="center" valign="middle">
                <td class="main"><div align="center"><strong>Contact Name</strong>*</div></td>
                <td colspan="2"><input type="text" name="ContactName" size="30" /></td>
              </tr>
              <tr align="center" valign="middle">
                <td class="main"><div align="center"><strong>City</strong></div></td>
                <td colspan="2"><input type="text" name="City" size="30" /></td>
              </tr>
              <tr align="center" valign="middle">
                <td class="main"><div align="center"><strong>State</strong></div></td>
                <td colspan="2"><input type="text" name="State" size="30" /></td>
              </tr>
              <tr align="center" valign="middle">
                <td class="main"><div align="center"><strong>Zip</strong>*</div></td>
                <td colspan="2"><input type="text" name="Zip" size="30" /></td>
              </tr>
              <tr align="center" valign="middle">
                <td class="main"><div align="center"><strong>Phone</strong>*</div></td>
                <td colspan="2"><input type="text" name="Phone" size="30" /></td>
              </tr>
              <tr align="center" valign="middle">
                <td class="main"><div align="center"><strong>Email</strong>*</div></td>
                <td colspan="2"><input type="text" name="Email" size="30" /></td>
              </tr>
              <tr align="center" valign="middle">
                <td class="main"><div align="center">How did you find us? </div></td>
                <td colspan="2"><input type="text" name="FromFind" size="30" /></td>
              </tr>
              <tr align="center" valign="middle">
                <td colspan="3" class="main"><div align="center"><strong>Comments or Questions?</strong></div></td>
              </tr>
              <tr align="center" valign="middle">
                <td colspan="3"><p align="center">
                    <textarea name="Comments" cols="55" rows="7" id="Comments"></textarea>
                 <div class="g-recaptcha" data-sitekey="here is the site key"></div>


                    </p></td>
              </tr>
              <tr align="center" valign="middle">
                <td colspan="2"><p align="left"><strong>*</strong>= Required field </p></td>
                <td><input name="submit" type="submit" value="Submit Form" /></td>
              </tr>
              <tr align="center" valign="middle">
                <td colspan="3" class="main">&nbsp;</td>
              </tr>
            </table>
          </form>

1 个答案:

答案 0 :(得分:1)

您的Web服务器可能阻止了您的file_get_contents命令。这可以通过检查&#39; allow_url_fopen&#39;是否在phpinfo详细信息中进行验证。指令是关闭的。如果是,则file_get_contents不起作用。

过去遇到过这个问题,我不得不使用curl来验证验证过程,以替代file_get_contents。

xampp