Javascript 我不知道';我不知道为什么google recaptcha是';我不能在我的php电子邮件表单中工作

Javascript 我不知道';我不知道为什么google recaptcha是';我不能在我的php电子邮件表单中工作,javascript,php,forms,email,recaptcha,Javascript,Php,Forms,Email,Recaptcha,我使用了以下步骤指南: 但是由于某种原因,recaptcha没有在网站上打电话/显示 我使用以下命令调用了页脚中的脚本: <script src='https://www.google.com/recaptcha/api.js' async defer > 我曾尝试将PHP代码放在电子邮件表单的正上方,但仍然没有成功。因此,我将其分离,并将其放入单独的send_form_email.php页面 这是我实施recaptcha的电子邮件表单: <form name="con

我使用了以下步骤指南:

但是由于某种原因,recaptcha没有在网站上打电话/显示

我使用以下命令调用了页脚中的脚本:

<script src='https://www.google.com/recaptcha/api.js' async defer >

我曾尝试将PHP代码放在电子邮件表单的正上方,但仍然没有成功。因此,我将其分离,并将其放入单独的send_form_email.php页面

这是我实施recaptcha的电子邮件表单:

<form name="contactform" method="post" action="send_form_email.php" class="mb-0">
                <div class="row">
                    <div class="col-md-6">

                        <input type="text" class="form-control" name="first_name" maxlength="50" placeholder="First Name: *" required>
                    </div>
                    <div class="col-md-6">
                      <input  type="text" class="form-control" name="last_name" maxlength="50" size="30" placeholder="Last Name:">

                    </div>

                    <div class="col-md-6">

                    <input type="text" class="form-control" name="telephone" maxlength="50" placeholder="Phone:">
                    </div>

                    <div class="col-md-6">
                    <input type="email" class="form-control" name="email"  maxlength="80" placeholder="Email: *" required>

                    </div>
                    <div class="col-md-12">
                        <textarea class="form-control" name="comments" rows="3" maxlength="1000" placeholder="Message: *" required></textarea>
                    </div>
                    <div class="g-recaptcha col-md-12" data-sitekey="6LexIpoUAAAAAMMftZIWNkik8IqsLfZDCKQxO9XO"></div>
                    <div class="col-md-12">
                        <input type="submit" value="Send Now" name="Submit" class="btn btn--secondary btn--rounded">
                    </div>
                </div>
            </form>

这是sendemail php文件:

<?php

if(isset($_POST['email'])) {

    // EDIT THE 2 LINES BELOW AS REQUIRED
    $email_to = "[REMOVED]";
    $email_subject = "Emailed from Webform";

    function died($error) {
        // your error code can go here
        echo "We are very sorry, but there were error(s) found with the form you submitted. ";
        echo "These errors appear below.<br /><br />";
        echo $error."<br /><br />";
        echo "Please go back and fix these errors.<br /><br />";
        die();
    }


    // validation expected data exists
    if(!isset($_POST['first_name']) ||
        !isset($_POST['last_name']) ||
        !isset($_POST['email']) ||
        !isset($_POST['telephone']) ||
        !isset($_POST['comments'])) {
        died('We are sorry, but there appears to be a problem with the form you submitted.');       
    }



    $first_name = $_POST['first_name']; // required
    $last_name = $_POST['last_name']; // required
    $email_from = $_POST['email']; // required
    $telephone = $_POST['telephone']; // not required
    $comments = $_POST['comments']; // required

    $error_message = "";
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';

  if(!preg_match($email_exp,$email_from)) {
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
  }

    $string_exp = "/^[A-Za-z .'-]+$/";

  if(!preg_match($string_exp,$first_name)) {
    $error_message .= 'The First Name you entered does not appear to be valid.<br />';
  }

  if(!preg_match($string_exp,$last_name)) {
    $error_message .= 'The Last Name you entered does not appear to be valid.<br />';
  }

  if(strlen($comments) < 2) {
    $error_message .= 'The Comments you entered do not appear to be valid.<br />';
  }

  if(strlen($error_message) > 0) {
    died($error_message);
  }


  if(isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response']))
  {
        $secret = '[REMOVED]';
        $verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secret.'&response='.$_POST['g-recaptcha-response']);
        $responseData = json_decode($verifyResponse);
        if($responseData->success)
        {
            $succMsg = 'Your contact request have submitted successfully.';
        }
        else
        {
            $errMsg = 'Robot verification failed, please try again.';
        }
   }




    $email_message = "Form details below.\n\n";


    function clean_string($string) {
      $bad = array("content-type","bcc:","to:","cc:","href");
      return str_replace($bad,"",$string);
    }



    $email_message .= "First Name: ".clean_string($first_name)."\n";
    $email_message .= "Last Name: ".clean_string($last_name)."\n";
    $email_message .= "Email: ".clean_string($email_from)."\n";
    $email_message .= "Telephone: ".clean_string($telephone)."\n";
    $email_message .= "Comments: ".clean_string($comments)."\n";

// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);  
?>

<!-- include your own success html here -->

<p>Thank you for contacting us. We will be in touch with you very soon.</P>
<?php

}
?>

感谢您联系我们。我们将很快与您联系。


根据教程,它应该显示一个代码。实际上它不是。

action=“send\u form\u email.php”
文件名是
sendmail.php
。php文件的确切名称是什么?抱歉,我指的是它的“send_form_email.php”是一个打字错误。您的浏览器控制台中有任何错误吗?没有。您可以在这里查看www.mariumarif.co.ukIn您的脚本标记中查看我在
之前看到的recaptcha api,因此这可能与此有关。尝试将recaptcha api脚本放入
标记中,并将recaptcha div嵌套在col md-*容器中。
action=“send_form_email.php”
文件名为
sendmail.php
。php文件的确切名称是什么?抱歉,我指的是它的“send_form_email.php”是一个打字错误。您的浏览器控制台中有任何错误吗?没有。您可以在这里查看www.mariumarif.co.ukIn您的脚本标记中查看我在
之前看到的recaptcha api,因此这可能与此有关。尝试将recaptcha api脚本放入
标记中,并将recaptcha div嵌套在col md-*容器中。