Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php google recaptcha和表单不起作用_Php_Forms_Recaptcha_Contacts - Fatal编程技术网

Php google recaptcha和表单不起作用

Php google recaptcha和表单不起作用,php,forms,recaptcha,contacts,Php,Forms,Recaptcha,Contacts,我试图在我的网站上实现google recaptcha。但由于某些原因,它不起作用。表格未提交。此外,验证码重新检查错误不起作用。我还插入了我的google recaptcha密钥 我在网上找到了验证码 我做错了什么 <?php if ( isset( $_POST[ 'g-recaptcha-response' ] ) && $_POST[ 'g-recaptcha-response' ] ) { var_dump( $_POST ); $secret

我试图在我的网站上实现google recaptcha。但由于某些原因,它不起作用。表格未提交。此外,验证码重新检查错误不起作用。我还插入了我的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>

公司名称
联系人姓名*
城市
状态
Zip*
电话*
电子邮件*
你是怎么找到我们的?
评论或问题?

*=必填字段


您的web服务器可能正在阻止您的文件获取内容命令。通过检查“allow\u url\u fopen”指令是否关闭,可以在phpinfo详细信息中验证这一点。如果是,则文件获取内容将无法工作

在过去遇到过这个问题,我不得不使用curl来让验证过程正常工作,作为文件内容的替代

$ch = curl_init();
curl_setopt_array($ch, [
    CURLOPT_URL => 'https://www.google.com/recaptcha/api/siteverify',
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => [
        'secret' => $secret,
        'response' => $captcha,
        'remoteip' => $ip
        ],
    CURLOPT_RETURNTRANSFER => true
    ]);

$output = curl_exec($ch);
curl_close($ch);

$arr = json_decode($output);

if ( $arr->success !== true ) {
    //Submission errored out
    }
else {
    //Send Email
    }

如果表单未提交,则显示表单可能会很有用。另外,请考虑不包括私钥。这将是明智的改变关键,因为一些机器人或用户可能已经刮了它,现在可以使用它了。谢谢