场景:
我的网站上有一个联系表单,它收到了很多垃圾邮件。
我宽松地验证了电子邮件地址的格式,即^.+@.+\..+$
我正在使用一个垃圾邮件过滤服务(defensio),但返回的垃圾邮件分数与有效邮件重叠。在0.4的阈值下,一些垃圾邮件会通过,一些客户的问题会被错误地记录并显示错误。
所有垃圾邮件都使用假电子邮件地址,例如zxmzxm@ywduasm.com
美国的专用PHP5 Linux服务器,mysql,仅记录垃圾邮件,向非垃圾邮件发送电子邮件(未存储)。
建议:
使用php的checkdnsrr(preg_replace(/^.+?@/, '', $_POST['email']), 'MX')
检查邮件域名是否解析为有效地址,记录到文件中,然后对于不能解析的邮件,重定向并显示错误,对于根据checkdnsrr()
可以解析的地址,继续使用垃圾邮件过滤服务。
我已经阅读了(我自己也持怀疑态度)你不应该把这种验证交给远程查询,但为什么?
除了连接问题,我会有比联系表单更大的问题之外,checkdnsrr是否会遇到误报/漏报?
是否会有某些地址类型无法解析?政府地址?ip电子邮件地址?
我需要转义传递给checkdnsrr()的主机名吗?
解决方案: 采用所有三个答案的组合(希望我可以接受不止一个作为复合答案)。
我正在使用:
$email_domain = preg_replace('/^.+?@/', '', $email).'.';
if(!checkdnsrr($email_domain, 'MX') && !checkdnsrr($email_domain, 'A')){
//validation error
}
所有垃圾邮件都已被记录并进行了轮换。目的是为了日后升级到作业队列。
有些评论提到向邮件服务器请求用户进行验证,但我觉得这会产生太多流量,可能会导致我的服务器被禁止或以某种方式陷入麻烦,而且这只是为了消除由于无效服务器地址而导致的大部分电子邮件被退回的问题。
http://en.wikipedia.org/wiki/Fqdn和
RFC2821
The lookup first attempts to locate an MX record associated with the name.
If a CNAME record is found instead, the resulting name is processed as if
it were the initial name.
If no MX records are found, but an A RR is found, the A RR is treated as
if it was associated with an implicit MX RR, with a preference of 0,
pointing to that host. If one or more MX RRs are found for a given
name, SMTP systems MUST NOT utilize any A RRs associated with that
name unless they are located using the MX RRs; the "implicit MX" rule
above applies only if there are no MX records present. If MX records
are present, but none of them are usable, this situation MUST be
reported as an error.
十分感谢所有人的帮助(特别是 ZoogieZork 提供的 A 记录后备提示)。