我的网站有以下代码来发送电子邮件。
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/