Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.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 我必须多等几秒钟才能通过contactform有效地发送消息_Php_Xml_Recaptcha - Fatal编程技术网

Php 我必须多等几秒钟才能通过contactform有效地发送消息

Php 我必须多等几秒钟才能通过contactform有效地发送消息,php,xml,recaptcha,Php,Xml,Recaptcha,我制作了一个联系表单,它使用Google recaptcha(用于垃圾邮件安全)向我的电子邮件发送消息。现在,当我填写所有字段时,选中“我不是机器人”框,然后尝试发送消息“我没有收到任何消息”。但当我等待3-4秒,然后发送消息时,我成功地将消息发送到我的电子邮件地址。我还检查了“inspect element”中的“network”属性,似乎一切都正常。我还将提供来自php的代码 我在不同的浏览器(包括隐姓埋名模式)和设备中尝试了这一点,但没有任何帮助,也似乎没有提示可能的解决方案 <?p

我制作了一个联系表单,它使用Google recaptcha(用于垃圾邮件安全)向我的电子邮件发送消息。现在,当我填写所有字段时,选中“我不是机器人”框,然后尝试发送消息“我没有收到任何消息”。但当我等待3-4秒,然后发送消息时,我成功地将消息发送到我的电子邮件地址。我还检查了“inspect element”中的“network”属性,似乎一切都正常。我还将提供来自php的代码

我在不同的浏览器(包括隐姓埋名模式)和设备中尝试了这一点,但没有任何帮助,也似乎没有提示可能的解决方案

<?php

    $public_key = "MyPublicKey";
    $private_key = "MyPrivateKey"; 
    $url = "https://www.google.com/recaptcha/api/siteverify"; 


    /* Check if the form has been submitted */
    if(array_key_exists('submit_form',$_POST))
    {
        /* The response given by the form being submitted */
        $response_key = $_POST['g-recaptcha-response'];
        /* Send the data to the API for a response */
        $response = file_get_contents($url.'?secret='.$private_key.'&response='.$response_key.'&remoteip='.$_SERVER['REMOTE_ADDR']);
        /* json decode the response to an object */
        $response = json_decode($response);

        /* if success */
        if($response->success == 1)
        {   
        $name = $_POST['name'];
            $secret = $_POST['MyPrivateKey'];
            $response = $_POST['g-recaptcha-response'];
            $email = $_POST['email'];
            $message = $_POST['message']; 

            $check_list = "Package(s):  ".implode(" ", $_POST['check_list'])."\n";

            $formcontent="From: $name \n $check_list \n Message: $message";
            $recipient = "email@gmail.com";
            $mailheader = "Message from contact form: $email \r\n";
            mail($recipient, $email, $formcontent, $mailheader) or die("Error!");
            echo 'Mail sent!';
        }
        else
        {
            echo 'Error, please try again!';
        }
    }

?>


我猜这里的坏人是
文件获取内容
你必须等待-但是当我等待3-4秒时。。。你这到底是什么意思?@B001ᛦ 感谢您的回复!我试着更好地解释它。第一个例子:我填写所有字段,选中recaptcha框,等待它加载,然后提交我的表单,但我的电子邮件中没有收到任何消息。第二个示例:我填写所有字段,检查repatcha wait直到加载,但这次我在提交表单之前等待了3-4秒,然后收到邮件。您的代码中是否有其他ajax功能,我们在这里没有看到?@B001ᛦ 不,这是我的网站使用的所有php代码,没有使用其他ajax功能。我猜这里的坏人是
file\u get\u contents
,你必须等待-但是当我等待3-4秒时。。。你这到底是什么意思?@B001ᛦ 感谢您的回复!我试着更好地解释它。第一个例子:我填写所有字段,选中recaptcha框,等待它加载,然后提交我的表单,但我的电子邮件中没有收到任何消息。第二个示例:我填写所有字段,检查repatcha wait直到加载,但这次我在提交表单之前等待了3-4秒,然后收到邮件。您的代码中是否有其他ajax功能,我们在这里没有看到?@B001ᛦ 不,这是我的网站使用的全部php代码,没有使用其他ajax功能。