我必须等待几秒钟,才能通过contactform有效发送消息

时间:2019-05-08 09:34:56

标签: php xml recaptcha

我制作了联系表格,该表格使用Google Recaptcha(用于垃圾邮件安全)将邮件发送到我的电子邮件。现在,当我填写所有字段时,选中“我不是机器人”框,然后尝试发送消息,我没有收到任何消息。但是,当我等待3-4秒然后发送邮件时,我成功地将邮件接收到了我的电子邮件地址。我还检查了“检查元素”中的“网络”属性,似乎一切正常。我还将提供来自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!';
        }
    }

?>

0 个答案:

没有答案