如何将recaptcha添加到mailform

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何将recaptcha添加到mailform相关的知识,希望对你有一定的参考价值。

已故朋友的妻子的网站被滥用于发送垃圾邮件。这可能是因为ReCaptcha未与注册表一起使用。该网站使用Joomla 3.9。

我想添加ReCaptcha,但我不知道如何做到这一点。

我希望有人能帮帮忙。

我自己没有尝试过任何东西,因为我对php的了解还不够好。

这是表格:

<form id="form1" action="/script/mailforms/mailsend.php" enctype="multipart/form-data" method="post"><input name="redirect" type="hidden" value="/bedankt" />
 <table border="0" width="200">
 <tbody>
 <tr>
 <td> </td>
 <td><strong>Gegevens ouder/verzorger</strong></td>
 <td> </td>
 <td> </td>
 <td><strong>Gegevens kind</strong></td>
 </tr>
 <tr>
 <td>Voornaam</td>
 <td><span id="sprytextfield1"> <label for="Naam"></label> <input id="Naam" name="Naam" type="text" /> </span></td>
 <td> </td>
 <td>Naam kind</td>
 <td><span id="sprytextfield9"> <label for="Naam Kind"></label> <input id="Naam Kind" name="Naam Kind" type="text" /> </span></td>
 </tr>
 <tr>
 <td>Achternaam</td>
 <td><span id="sprytextfield2"> <label for="Achternaam"></label> <input id="Achternaam" name="Achternaam" type="text" /> </span></td>
 <td> </td>
 <td>Geslacht</td>
 <td><span id="spryradio1"> <label> <input id="Geslacht_0" name="Geslacht" type="radio" value="Jongen" /> jongen</label> <br /> <label> <input id="Geslacht_1" name="Geslacht" type="radio" value="Meisje" /> meisje</label> <br /> </span></td>
 </tr>
 <tr>
 <td>Straat + nr</td>
 <td><span id="sprytextfield3"> <label for="Straat en nr"></label> <input id="Straat en nr" name="Straat en nr" type="text" /> </span></td>
 <td> </td>
 <td>Geboortedatum</td>
 <td><span id="sprytextfield10"> <label for="Geboortedatum"></label> <input id="Geboortedatum" name="Geboortedatum" type="text" /> </span></td>
 </tr>
 <tr>
 <td>Postcode</td>
 <td><span id="sprytextfield4"> <label for="Postcode"></label> <input id="Postcode" name="Postcode" type="text" /> </span></td>
 <td> </td>
 <td>Schoolnaam</td>
 <td><span id="sprytextfield11"> <label for="Schoolnaam"></label> <input id="Schoolnaam" name="Schoolnaam" type="text" /> </span></td>
 </tr>
 <tr>
 <td>Woonplaats</td>
 <td><span id="sprytextfield5"> <label for="Woonplaats"></label> <input id="Woonplaats" name="Woonplaats" type="text" /> </span></td>
 <td> </td>
 <td>Voorkeur</td>
 <td><span id="spryradio2">  <br /> <label> <input id="Voorkeur_1" name="Voorkeur" type="radio" value="Woensdag" /> Woensdagmiddag (Zonnestudio)</label> <br /> </span></td>
 </tr>
 <tr>
 <td>Telefoonnr</td>
 <td><span id="sprytextfield6"> <label for="Telefoonnr"></label> <input id="Telefoonnr" name="Telefoonnr" type="text" /> </span></td>
 <td> </td>
 <td> </td>
 <td> </td>
 </tr>
 <tr>
 <td>Email</td>
 <td><span id="sprytextfield7"> <label for="Email"></label> <input id="Email" name="Email" type="text" /> </span></td>
 <td> </td>
 <td>Bijzonderheden</td>
 <td><span id="sprytextarea1"> <label for="Bijzonderheden"></label>      <textarea id="Bijzonderheden" cols="45" name="Bijzonderheden" rows="5">     </textarea> </span></td>
 </tr>
 <tr>
 <td>Bank/gironr</td>
 <td><span id="sprytextfield8"> <label for="Bankgiro"></label> <input id="Bankgiro" name="Bankgiro" type="text" /> </span></td>
 <td> </td>
 <td> </td>
 <td> </td>
 </tr>
 <tr>
 <td> </td>
 <td colspan="4"><br /><span id="sprycheckbox1"> <input id="Algemene Voorwaarden" name="Algemene Voorwaarden" type="checkbox" /> </span>Ik heb de de <strong><a href="over-de-zwemschool/algemene-voorwaarden-de-zwemschool" target="_blank" rel="noopener noreferrer">algemene voorwaarden</a></strong> gelezen en ga hiermee akkoord</td>
 </tr>
 <tr>
 <td> </td>
 <td><input id="Verzenden" name="Verzenden" type="submit" value="Verzenden" /></td>
 <td> </td>
 <td> </td>
 <td> </td>
 </tr>
 </tbody>
 </table>
</form>

这是mailsend.php:

<?php   
require('class.mailer.info.php');

//phpinfo();

/* Vaste post waarden vastleggen */
// ontvanger
if(empty($_POST['redirect']))
{   
    die("error: geen ontvanger vastgelegd en redirect pad.");
}


// Instantiate your new class
$mail = new HeartmedicalMailer;

/*
Verwerken post informatie
*/
$body_text = '';

// waardes die je niet wilt tonen wegfilteren als redirect / receipient etc.
$excluded = array('redirect');

// html opmaak formulier voor loop
$body_text .= "<style>body{ font-family:Verdana, Arial; font-size:11px; color:#000000; }</style>";

// loop doorlopen met opmaak
foreach($_POST as $key => $value)
{
    // vaste waardes wegfilteren
    if(!in_array($key, $excluded))
    {
        if(!empty($value))
        {   
            $key = preg_replace('#_#',' ', $key);

            $body_text .= '<strong>'.$key.'</strong>:  '.$value.'<br>';
        }
    }
}   

// Now you only need to add the necessary stuff
$mail->Body = $body_text;

if(!$mail->Send())
{
    echo "Mailer Error: " . $mail->ErrorInfo;
    die("There was an error sending the message #code1");
} 

// redirect
header("Location: ".$_POST['redirect']." ");        
?>

这是class.mailer.info.php:

<?php
// class phpmailer
require("../phpmailer/class.phpmailer.php");

class HeartmedicalMailer extends PHPMailer 
{
    // Set default variables for all new objects
    var $From     = "xxxxx@xxxxx.nl";
    var $FromName = "De Zwemschool";
    var $Host     = "localhost";
    /* smtp auth */
    var $Mailer   = "smtp"; // Alternative to IsSMTP()
    var $SMTPAuth = false;     // turn on SMTP authentication
    var $Username = "";  // SMTP username
    var $Password = ""; // SMTP password

    var $WordWrap = 75;
    var $Subject  = "Inschrijving De Zwemschool";

    function HeartmedicalMailer() 
    {

                    $this->AddAddress('xxxx@xxxx.nl', 'Name');


        $this->IsHTML(true);
    }

    // Replace the default error_handler
    function error_handler($msg) {
        print("Mailer Error");
        print("Description:");
        printf("%s", $msg);
        exit;
    }
}
?>

我想将表格与recaptcha一起发送

答案

您可以使用Google reCAPTCHA。

我个人使用reCAPTACHA V2隐形,所以你会在下面找到一个例子。

首先得到钥匙:link

然后用以下代码替换您的提交输入:

<button class="g-recaptcha form-control" data-sitekey="YOUR_RECAPTCHA_KEY" data-callback='onSubmit'>Send</button>

然后将这些脚本添加到HTML页面:

<script src="https://www.google.com/recaptcha/api.js" async defer></script>
<script>
  function onSubmit(token) {
    document.getElementById("form1").submit();
  }
</script>

最后在qazxsw poi的开头添加:

mailsend.php

希望能帮助到你 ;)

以上是关于如何将recaptcha添加到mailform的主要内容,如果未能解决你的问题,请参考以下文章

php 使用AJAX将google recaptcha添加到我们的表单中

如何将 Google Recaptcha v2 实施到限制访问 Google Recaptcha 的 Web 应用程序

如何使用网络爬虫提前解决 reCaptcha? [关闭]

如何在 vuetify 上添加 google recaptcha 3?

当单个页面上存在 2 个表单时,如何使用 jQuery 表单验证插件验证 reCaptcha?

如何在模态对话框中键盘导航到reCAPTCHA?