在我的php网站上没有工作google recaptcha

时间:2017-03-23 04:41:31

标签: php html recaptcha

我使用bluehost作为我的网络服务器。 我正在尝试将reCAPTCHA实现到我的网站的电子邮件表单中, 邮件是在不通过重新接收的情况下发送的。

以下是一些HTML代码。

<div class="letterbox">
    <form method="post" name="enewsform" id="enewsform" action="enewsletter_ins.php">
    <h3 class="tit2">Subscribe To Newsletter</h3>
    <div style="margin-top:10px;">
        <label class="tit2">Name 
          <input type="text" name="name" value="" /></label>
        <label class="tit2">Email Address 
          <input type="text" name="email" value="" /></label></br>
          <div class="g-recaptcha" data-sitekey="itmysitekey!!"></div>
        <input type="button" value="subscribe" class="btn_letter"  onclick="sendData(document.enewsform)" />
    </div>
    </form>
    <script type="text/javascript">
    <!--
        function sendData(f){
            if(f.name.value==""){
                alert("Required to name.");
                f.name.focus();
                return false;
            }
            if(f.email.value==""){
                alert("Required to email.");
                f.email.focus();
                return false;
            }
            if (f.email.value.search(/(\S+)@(\S+)\.(\S+)/) == -1 ) {
               alert("Not Valid Email."); 
                f.email.focus();
               return false;
            }
            f.submit();
        }
    //-->
    </script>

下面是一些php代码。

<?
include_once $_SERVER[DOCUMENT_ROOT]."/include/initiate.php";

if(trim($name)=="" or trim($email)==""){
    alert("send errer!!");
}

$form_title=$name." 님의 Subscribe to eNewsletter 신청";
$user_name=$name;
$user_email=$email;
$body="
date : ".date("Y-m-d H:i:s")."
<hr>
Name : $name
<hr>
E-Mail : $email
";

$sql = "
        insert into prd_form_data set
            form_type = '3',
            form_title = '".$form_title."',
            user_name = '".$user_name."',
            user_email = '".$user_email."',
            user_content = '".$body."',
            insdt = now()
";
mysql_query($sql) or error(mysql_error());

//메일발송
$comments = $body;

$mailTo     =   ADMIN_MAIL; // 받는 메일 주소;
$mailFrom   =   "inquiry@example.com";  //  

$mailSubject = "Subscribe to eNewsletter";
$mailContent = $comments;

$mailHeader = "From: $mailFrom\r\n";
$mailHeader .= "MIME-Version: 1.0\r\n";
$mailHeader .= "Content-type: text/html; charset=utf-8\r\n";

$mailResult = mail ($mailTo, $mailSubject, $mailContent, $mailHeader,'-f'.$mailFrom);

?>

<form method="post" action="/" name="frm">
</form>

<script type="text/javascript">
<!--
    alert("ok!!");
    document.frm.submit();
//-->
</script>

1 个答案:

答案 0 :(得分:1)

 
function sendData(f){
  if(f.name.value==""){
alert("Required to name.");
f.name.focus();
return false;
  }
  if(f.email.value==""){
alert("Required to email.");
f.email.focus();
return false;
  }
  if (f.email.value.search(/(\S+)@(\S+)\.(\S+)/) == -1 ) {
   alert("Not Valid Email."); 
   f.email.focus();
   return false;
  }
  if(document.forms["enewsform"]["g-recaptcha-response"].value==""){
alert("Please fill reCAPTCHA");
document.forms["enewsform"]["g-recaptcha-response"].focus();
return false;
  }
  f.submit();
 }          
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://www.google.com/recaptcha/api.js"></script>

<div class="letterbox">
    <form method="post" name="enewsform" id="enewsform" action="enewsletter_ins.php">
        <h3 class="tit2">Subscribe To Newsletter</h3>
        <div style="margin-top:10px;">
            <label class="tit2">Name
                <input type="text" name="name" value="" />
            </label>
            <br />
            <label class="tit2">Email Address
                <input type="text" name="email" value="" />
            </label>
            <br />
            <div class="g-recaptcha" data-sitekey="6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI"></div>
            <input type="button" value="subscribe" class="btn_letter" onclick="sendData(document.enewsform)" />
        </div>
    </form>
</div>