Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/239.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/85.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 echo函数不能在联系人表单上使用ajax_Php_Html_Css_Ajax - Fatal编程技术网

Php echo函数不能在联系人表单上使用ajax

Php echo函数不能在联系人表单上使用ajax,php,html,css,ajax,Php,Html,Css,Ajax,最近,我一直在尝试使用recaptcha支持制作一个html联系人表单,使用php上的echo生成fail&Success消息,问题是我不知道为什么它没有出现在css中。 但是,当我使用代码时,请检查验证码表单。在主网站上的有效性。 mail.php <?php if ($_SERVER["REQUEST_METHOD"] == "POST") { // access $secretKey = '

最近,我一直在尝试使用recaptcha支持制作一个html联系人表单,使用php上的echo生成fail&Success消息,问题是我不知道为什么它没有出现在css中。 但是,当我使用代码时,请检查验证码表单。

在主网站上的有效性。

mail.php

    <?php

    if ($_SERVER["REQUEST_METHOD"] == "POST") {

        // access
        $secretKey = '6LcEPdAaAAAAAHP4NLmyC1UNC5Ce9_0__gTaF5Im';
        $captcha = $_POST['g-recaptcha-response'];

        if(!$captcha){
          echo '<p class="alert alert-warning">Please check the the captcha form.</p>';
          exit;
        }

        # FIX: Replace this email with recipient email
        $mail_to = "soporte@steycian.com";
        
        # Sender Data
        $subject = trim($_POST["subject"]);
        $name = str_replace(array("\r","\n"),array(" "," ") , strip_tags(trim($_POST["name"])));
        $email = filter_var(trim($_POST["email"]), FILTER_SANITIZE_EMAIL);
        $phone = trim($_POST["phone"]);
        $message = trim($_POST["message"]);
        
        if ( empty($name) OR !filter_var($email, FILTER_VALIDATE_EMAIL) OR empty($phone) OR empty($subject) OR empty($message)) {
            # Set a 400 (bad request) response code and exit.
            http_response_code(400);
            echo '<p class="alert alert-warning">Please complete the form and try again.</p>';
            exit;
        }

        $ip = $_SERVER['REMOTE_ADDR'];
        $response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secretKey."&response=".$captcha."&remoteip=".$ip);
        $responseKeys = json_decode($response,true);

        if(intval($responseKeys["success"]) !== 1) {
          echo '<p class="alert alert-warning">Please check the the captcha form.</p>';
        } else {
            # Mail Content
            $content = "Name: $name\n";
            $content .= "Email: $email\n\n";
            $content .= "Phone: $phone\n";
            $content .= "Message:\n$message\n";

            # email headers.
            $headers = "From: $name <$email>";

            # Send the email.
            $success = mail($mail_to, $subject, $content, $headers);
            if ($success) {
                # Set a 200 (okay) response code.
                http_response_code(200);
                echo '<p class="alert alert-success">Thank You! Your message has been sent.</p>';
            } else {
                # Set a 500 (internal server error) response code.
                http_response_code(500);
                echo '<p class="alert alert-warning">Oops! Something went wrong, we couldnt send your message.</p>';
            }
        }

    } else {
        # Not a POST request, set a 403 (forbidden) response code.
        http_response_code(403);
        echo '<p class="alert alert-warning">There was a problem with your submission, please try again.</p>';
    }

?>

因为在某个地方,您的ajax代码可能会像这样插入HTML:

$('.ajax-response').text(result);
应该是什么时候

$('.ajax-response').html(result);

你刚刚发布了你的密钥,你会想要一个新的。我很确定验证验证码的hit应该是一个POST,而不是get。这与jQuery有什么关系?你可能也想接收那封电子邮件。你完全正确,我刚刚检查了我的ajax-form.js,我看到了你告诉我的内容并修复了它,谢谢。thx。继续吧,接受这个答案。干杯
$('.ajax-response').html(result);