php - 使用 PHP 和验证码减少垃圾邮件的最佳实践是什么?

标签 php captcha

我的网站有以下代码来发送电子邮件。

if($_SESSION["captcha"]==$_POST["captcha"])
{

$msg="Require Services :\t$_POST[service]\n";
$msg="Name :\t$_POST[name]\n";
$msg.="Company Name :\t$_POST[co_name]\n";
$msg.="Address :\t$_POST[address]\n";
$msg.="Mobile :\t$_POST[mobile]\n";
$msg.="Phone :\t$_POST[phone]\n";
$msg.="E-mail :\t$_POST[email]\n";
$msg.="Message :\t$_POST[message]\n";

$subject=$_POST[subject];
$to="<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d0b9beb6bf90a3a2b9a2b1bda4a2b1b4b5feb3bfbd" rel="noreferrer noopener nofollow">[email protected]</a>,<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d3a1b2b9be8ce2e1e093a1b6b7bab5b5beb2babffdb0bcbe" rel="noreferrer noopener nofollow">[email protected]</a>";
$headers="From: $_POST[email] < $_POST[email]> \n";
$headers .= "Reply-To: $_POST[email]\n\n";

mail($to,$subject,$msg,$headers);}

?>

即使使用验证码减少垃圾邮件后,我仍然收到很多垃圾邮件。

最佳答案

添加一个新的输入字段,将其标记为“请留空”,使用 CSS 隐藏它,如果该字段已填写,则忽略该帖子。如下所示:

<style type='text/css'>
#other_email_label, #other_email {
    display: none;
}
</style>
...
<form action='mail'>
<label id='other_email_label' for='other_email'>Please leave blank:</label>
<input type='text' name='other_email' id='other_email'>
...
</form>

因此,人类不会看到该字段(除非他们关闭了 CSS,在这种情况下,他们会看到标签并将其留空),但垃圾邮件机器人会填写该字段。填充该字段的任何帖子一定来自垃圾邮件机器人。

关于php - 使用 PHP 和验证码减少垃圾邮件的最佳实践是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/788328/

相关文章:

php - 声明一个可选的数组参数

php - 当PHP出现解析错误时,如何运行自定义函数/部分代码

java - 如何在jsp表单中插入验证码?

javascript - Angular:尝试添加验证码。错误 => 没有名称为 'captcha' 的表单控件的值访问器

javascript - ReCaptcha API v2 样式

javascript - 即使你没有调用函数也会运行

php - 使用 php 和 PDO 将数组值插入单个 ID 到 mysql 数据库中

html - 使用 Google 的 reCaptcha 保护下载链接免受机器人攻击

captcha - 阻止垃圾邮件发送者创建帐户(reCaptcha 不起作用)

php - 树莓派相机流媒体不会从 php 开始