Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/232.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
如何用HTML+;PHP验证_Php_Html_Forms_Validation_Recaptcha - Fatal编程技术网

如何用HTML+;PHP验证

如何用HTML+;PHP验证,php,html,forms,validation,recaptcha,Php,Html,Forms,Validation,Recaptcha,我试图在一个带有PHP验证的HTML页面上实现GoogleReCAPTCHAV2,但是我还没有通过验证。我总是收到错误“无效验证码。请重试” 我确信我的站点和密钥都可以 请查看我的代码: HTML标题: <html> <head> <script src='https://www.google.com/recaptcha/api.js?hl=es'></script> </head> HTML表单 <form ac

我试图在一个带有PHP验证的HTML页面上实现GoogleReCAPTCHAV2,但是我还没有通过验证。我总是收到错误“无效验证码。请重试”

我确信我的站点和密钥都可以

请查看我的代码:

HTML标题:

<html>
<head>

    <script src='https://www.google.com/recaptcha/api.js?hl=es'></script>
</head>

HTML表单

<form action="mail_handler01.php" method="post">
<table border="0" cellpadding="2" cellspacing="0" width="100%">

<tbody>
    <tr>
        <td class="text1" width="63">
            <div align="right">Nombre</div>
            </td>
            <td class="text1" width="3"></td>
            <td class="text1"><input name="name" size="24" type="text" /></td>
        </tr>
        <tr>
            <td class="text1" width="63">
            <div align="right">E-mail</div>
            </td>
            <td width="3"></td>
            <td><input name="de" size="24" type="text" /></td>
        </tr>
        <tr>
            <td class="text1" width="63">
            <div align="right">Asunto</div>
            </td>
            <td width="3"></td>
            <td><input name="subject" size="24" type="text" /></td>
        </tr>
        <tr>
            <td class="text1" width="63">
            <div align="right">Tel&eacute;fono</div>
            </td>
            <td width="3"></td>
            <td><input name="tel" size="24" type="text" /></td>
        </tr>
        <tr height="5">
            <td class="text1" height="5" width="63"></td>
            <td height="5" width="3"></td>
            <td height="5"></td>
        </tr>
        <tr>
            <td width="63"></td>
            <td width="3"></td>
            <td><textarea cols="22" name="body" rows="8"></textarea></td>
        </tr>
        <tr>
            <td width="63"></td>
            <td width="3"></td>
            <td width="190">
            <div class="g-recaptcha" data-sitekey="here I pasted my sitekey" data-size="compact" ></div>
            <!-- this will show captcha errors --></td>
        </tr>
        <tr>
            <td width="63"></td>
            <td width="3"></td>
            <td><input name="submit" type="submit" value=":: Enviar ::" /></td>
        </tr>
    </tbody>
</table>
&#39;</form>

名义
电子邮件
阿松托
电话é;福诺
'
mailhandler01.php

<?php
    if (isset($_POST["submit"])) {

        $url = 'https://www.google.com/recaptcha/api/siteverify';
        $privatekey = "here I pasted my private key";

        $response = file_get_contents($url."?secret=".$privatekey."&response=".$_POST['g-recaptcha-response']);
        $data = json_decode($response);

        if(isset($data->success) AND $data->success==true){
            $to = "info@mydomain.com";
            $email = $_POST['de'];
            $full_name = $_POST['name'];
            $subject = $_POST['subject'];
            $phone = $_POST['tel'];
            $body = $_POST['body'];
            
            $message = "
            <html>
            <head>
            <title>".$subject."</title>
            </head>
            <body>
            <p>Nombre: $full_name</p>
            <p>Correo: $email</p>
            <p>Tel: $phone</p>
            <p>Mensaje: $body</p>
            </body>
            </html>
            ";
            // Always set content-type when sending HTML email
            $headers = "MIME-Version: 1.0" . "\r\n";
            $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

            // More headers
            $headers .= 'From: kauto@mydomain.com' . "\r\n";


            if(mail($to, $subject, $message, $headers)){
                echo "<script> alert('Gracias por su mensaje. Pronto estaremos en contacto.'); window.location.href='contact.php'; window.location.href='index.html'; </script>";
            }else{
                echo "mail could not be sent";
            }
        }else{
            echo "Invalid captcha. Please try again";
        }

    }else{
        echo '<h2 class="text center">User has not submitted the form</h2>';
    }

 ?>