使用PHP PEAR邮件类检查域是否存在

使用PHP PEAR邮件类检查域是否存在,php,email,pear,Php,Email,Pear,我注意到我的服务器在尝试向无效域发送电子邮件时返回此错误: Standard Message: Failed to set sender: user@invaliddomain.coom [SMTP: Invalid response code received from server (code: 553, response: 5.1.8 ... Domain of sender address user@invaliddomain.coom does not exist)] Standa

我注意到我的服务器在尝试向无效域发送电子邮件时返回此错误:

Standard Message:   Failed to set sender: user@invaliddomain.coom [SMTP: Invalid response code received from server (code: 553, response: 5.1.8 ... Domain of sender address user@invaliddomain.coom does not exist)]
Standard Code:  10004
DBMS/User Message:  
DBMS/Debug Message:
有没有办法在发送电子邮件之前先检查域名?我有一种感觉,我也可以通过消除这个错误在SMTP服务器端处理这个问题,但我喜欢在发送电子邮件之前先测试电子邮件域的想法。谢谢你的想法

以下是仅供参考的相关代码(从表单中筛选变量):

您可以使用来确定该域是否存在,如果存在,请通过它的方式发送电子邮件

include "Net/DNS2.php";
$r = new Net_DNS2_Resolver();            
try {
    $result = $r->query($domain, 'MX');    
} catch(Net_DNS2_Exception $e) {
    $result = null;         
}
if ($result !== null) {
    // send email...
}

当然,我建议您使用某种级别的缓存,这样您就不会重复查找了。

谢谢kguest,我会试试这个!看起来是个好办法。我仍然想知道为什么我以前没有这个问题。。。
include "Net/DNS2.php";
$r = new Net_DNS2_Resolver();            
try {
    $result = $r->query($domain, 'MX');    
} catch(Net_DNS2_Exception $e) {
    $result = null;         
}
if ($result !== null) {
    // send email...
}