有没有办法通过PHP检查指定的电子邮件地址是否处于活动状态(即是否有任何人正在使用和打开它),或者不是(即被阻止或没有人使用/打开它,它是无效的)?
提前致谢。
我认为您正在询问电子邮件用户输入的是否有效!如果是这种情况,那么您应该使用nslookup来帮助Unix操作系统执行。以下是一个小函数:(我正在检查域名是否正确)
function myCheckDNSRR($email)
{
list($userName, $hostName) = split("@", $email);
$recType = '';
if(!empty($hostName)) {
if( $recType == '' ) $recType = "MX";
exec("nslookup -type=$recType $hostName", $result);
// check each line to find the one that starts with the host
// name. If it exists then the function succeeded.
foreach ($result as $line) {
if(eregi("^$hostName",$line)) {
return true;
}
}
// otherwise there was no mail handler for the domain
return false;
}
return false;
}
你可以使用外部服务的API,但必须使用API。
有一些电子邮件验证API可用,data8就是其中之一。http://www.data-8.co.uk/integr8/services/email_validation.aspx
这里是一个示例。
function IsValid($email, $level)
{
$params = array(
"username" => "your-username",
"password" => "your-password",
"email" => $email,
"level" => $level,
"options" => $options
);
$client = new SoapClient("http://webservices.data-8.co.uk/EmailValidation.asmx?WSDL");
$result = $client->IsValid($params);
if ($result->IsValidResult->Status->Success == 0)
{
echo "Error: " . $result->IsValidResult->Status->ErrorMessage;
}
else
{
// TODO: Process method results here.
// Results can be extracted from the following fields:
// $result->IsValidResult->Result
// Contains a status code indicating if the email address could be validated.
}
}