如何获取reCaptcha返回联系人表单下(或结束) [英] How to get reCaptcha returns under (or over) the contact form

查看:102
本文介绍了如何获取reCaptcha返回联系人表单下(或结束)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在之前的问题中,我从@ADyson得到了如何在新的空白页面上获得回报的答案,这是一种解决方案,并且非常感谢。但我更愿意在该联系人页面的联系表格下获得它。我被告知要使用echo语句和if语句来完成此操作,但我不够聪明来管理它。我在网络主机one.com中使用网络构建器。我在联系页面的代码框中输入联系表单(我无法在html代码中进行更正,因为下次我使用web构建器发布内容时它已被覆盖)php文件位于文件的根目录经理。正如你告诉我的那样,我在php中添加了回显语句,现在回报显示在空白页面上。这是我的第一个目标,但正如我所说,我更喜欢用联系表单来获取它。



以下是我的form.php:

 <?phpif(isset($ _ POST ['submit'])&!empty($ _ POST ['submit'])):if(isset($ _ POST ['g-recaptcha-response' ])&&!empty($ _ POST ['g-recaptcha-response']))://你的站点密钥$ secret ='secret key'; //获取验证回复数据$ verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.secret.'&response='.$_POST ['g-recaptcha-响应']); $ responseData = json_decode($ verifyResponse); if($ responseData-> success)://联系表单提交代码$ name =!empty($ _ POST ['name'])?$ _ POST ['name']:''; $ email =!empty($ _ POST ['email'])?$ _ POST ['email']:''; $ message =!empty($ _ POST ['message'])?$ _ POST ['message']:''; $ to ='kontakt@boakustikk.no'; $ subject ='新的联系表单已提交'; $ htmlContent =< h1>< h1> Henvendelse fra din hjemmeside< / h1>< p>< b> Navn:< / b>。$ name。< / p>< p>< b>电子邮件:< / b>。$ email。< / p>< p>< b>整合:< / b>$ message。< / p>; //发送HTML电子邮件时始终设置内容类型$ headers =MIME-Version:1.0。 \r\\\
; $ headers。=Content-type:text / html; charset = UTF-8。 \r\\\
; //更多标题$ headers。='From:'。$ name。'<'。$ email。'>'。 \r\\\
; //发送电子邮件@mail($ to,$ subject,$ htmlContent,$ headers); echo $ succMsg ='TAKK FOR MELDING。 VI KONTAKTER DEG SNAREST。'; else:echo $ errMsg ='ROBOT VERIFIKASJON GIKK GALT,GIL TILBAKE OGPRØVPAY NYTT。';万一; else:echo $ errMsg ='MELDINGEN BLE IKKE SENDT。 VENNLIGST G?TILBAKE OG KLIKK P?reCAPTCHA BOKS。'; endif; else:echo $ errMsg =''; echo $ succMsg =''; endif;?>

和这里是我的form.html:



< form action =form。 phpmethod =POST> < input type =textname =nameplaceholder =Ditt navnsize =43/>< br>< br> < input type =textname =emailplaceholder =Din E-postsize =43/>< br>< br> < textarea type =textname =messagerows =8cols =41>< / textarea>< br>< br> < div class =g-recaptchadata-sitekey =site key>< / div>< br> < input type =submitname =submitvalue =SEND MELDING>< / form>

p>

我会很乐意解决这个问题。



BR
Hans Kristian

解决方案

现在解决了!如果有人需要在One.com网站主机服务器上使用该代码,请告诉我。


In a earlier question I got an answer from @ADyson of how to get the returns on a new blank page and that is in a way a solution, and thanks a lot for that. But I would prefer to get it under the contact form on that spesific contact page.I was told to do it with echo statement and if statement, but I am not smart enough to manage that. I use a web builder in the web host one.com. I enter the contact form in a code box on the contact page (I can not do corrections in the html-codes because it is over written next time I publish something with the web builder) an the php-file in the root of the file manager. I added echo statements to the returns in php, as you told me, and now the returns shows up on a blank page.That was my first goal, but as I said I would prefer to get it under the contact form.

Here is my form.php:

<?php
if(isset($_POST['submit']) && !empty($_POST['submit'])):
    if(isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])):
        //your site secret key
        $secret = 'secret key';
        //get verify response data
        $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):
            //contact form submission code
            $name = !empty($_POST['name'])?$_POST['name']:'';
            $email = !empty($_POST['email'])?$_POST['email']:'';
            $message = !empty($_POST['message'])?$_POST['message']:'';
            
            $to = 'kontakt@boakustikk.no';
            $subject = 'New contact form have been submitted';
            $htmlContent = "
                <h1>Henvendelse fra din hjemmeside</h1>
                <p><b>Navn: </b>".$name."</p>
                <p><b>E-post: </b>".$email."</p>
                <p><b>Melding: </b>".$message."</p>
            ";
            // 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:'.$name.' <'.$email.'>' . "\r\n";
            //send email
            @mail($to,$subject,$htmlContent,$headers);

            echo$succMsg = 'TAKK FOR MELDING. VI KONTAKTER DEG SNAREST.';
        else:
            echo$errMsg = 'ROBOT VERIFIKASJON GIKK GALT, GÅ TILBAKE OG PRØV PÅ NYTT.';
        endif;
    else:
        echo$errMsg = 'MELDINGEN BLE IKKE SENDT. VENNLIGST GÅ TILBAKE OG KLIKK PÅ reCAPTCHA BOKS.';
    endif;
else:
    echo$errMsg = '';
    echo$succMsg = '';
endif;
?>

and here is my form.html:

<form action="form.php" method="POST">
    <input type="text" name="name"  placeholder="Ditt navn"  size="43" /><br><br>
    <input type="text" name="email" placeholder="Din E-post" size="43" /><br><br>
    <textarea type="text" name="message" rows="8" cols="41"></textarea><br><br>
    <div class="g-recaptcha" data-sitekey="site key"></div><br>
    <input type="submit" name="submit" value= "SEND MELDING">
</form>

I will be very happy to fix this issue.

BR Hans Kristian

解决方案

This case is now solved! If someone needs the codes for use on One.com web host server, please let me know.

这篇关于如何获取reCaptcha返回联系人表单下(或结束)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆