使用PHP-EHLO进行SMTP验证
我正在尝试进行电子邮件验证,但似乎无法进行验证。目前,它将连接到域,但之后它似乎超时。有人知道这是为什么吗?它好像挂在这里:使用PHP-EHLO进行SMTP验证,php,email,smtp,verification,Php,Email,Smtp,Verification,我正在尝试进行电子邮件验证,但似乎无法进行验证。目前,它将连接到域,但之后它似乎超时。有人知道这是为什么吗?它好像挂在这里: $res=fgets($connection, "EHLO $mydomain\n"); 有人能告诉我为什么会这样吗?我的代码如下: if(isset($_POST['email']) && filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) { // Could get this from th
$res=fgets($connection, "EHLO $mydomain\n");
有人能告诉我为什么会这样吗?我的代码如下:
if(isset($_POST['email']) && filter_var($_POST['email'], FILTER_VALIDATE_EMAIL))
{
// Could get this from the php ini?
$from="xxxx@xxxx-int.net";
$to=$_POST['email'];
$subject="Test";
$message="Testing";
list($me,$mydomain) = split("@",$from);
// Now look up the mail exchangers for the recipient
list($user,$domain) = split("@",$to,2);
if(getmxrr($domain,$mx,$weight) == 0) return FALSE;
// Try them in order of lowest weight first
array_multisort($mx,$weight);
$success=0;
foreach($mx as $host) {
// Open an SMTP connection
$connection = fsockopen ($host, 25, $errno, $errstr, 1);
if (!$connection)
continue;
$res=fgets($connection);
echo $res;
if(substr($res,0,3) != "220") echo $res;
// Introduce ourselves
fputs($connection, "EHLO $mydomain\n");
$res=fgets($connection);
echo $res;
if(substr($res,0,3) != "250") echo $res;
// Envelope from
fputs($connection, "MAIL FROM: $from\n");
$res=fgets($connection);
echo $res;
if(substr($res,0,3) != "250") echo $res;
// Envelope to
fputs($connection, "RCPT TO: $to\n");
$res=fgets($connection);
echo $res;
if(substr($res,0,3) != "250") echo $res;
// The message
fputs($connection, "DATA\n");
$res=fgets($connection);
echo $res;
if(substr($res,0,3) != "354") echo $res;
// Send To:, From:, Subject:, other headers, blank line, message, and finish
// with a period on its own line.
fputs($connection, "To: $to\nFrom: $from\nSubject: $subject\n$message\n.\n");
$res=fgets($connection);
echo $res;
if(substr($res,0,3) != "250") echo $res;
// Say bye bye
fputs($connection,"QUIT\n");
$res=fgets($connection);
echo $res;
if(substr($res,0,3) != "221") echo $res;
// It worked! So break out of the loop which tries all the mail exchangers.
$success=1;
break;
}
// Debug for if we fall over - uncomment as desired
// print $success?"Mail sent":"Failure: $res\n";
if($connection) {
if($success==0) fputs($connection, "QUIT\n");
fclose ($connection);
}
return $success?TRUE:FALSE;
}
您只在末尾发送换行符,但需要CRLF。这会导致脚本“挂起”,因为电子邮件服务器不会响应无效的行尾。
你得把这个改成
fputs($connection, "EHLO $mydomain\r\n");
等等
请注意,电子邮件验证在许多情况下都不起作用,即使您的脚本与RFC兼容的SMTP通信。许多服务器只是简单地接受(并在稍后反弹)所有发送给无效收件人的邮件。其他人在数据阶段进行收件人验证,而不是rcpt to(exchange 2013..sigh)等。当您可以使用PHPMailer或Swiftmailer继续工作时,为什么要编写自己的SMTP接口?这可能会妨碍早期通话者检测系统。您的代码似乎无法处理多行横幅。在您发送EHLO之前,$res的内容是什么?因为我会尝试将其设置为rcpt to:点,如果它产生错误550,则不允许它执行某些操作,否则如果rcpt to:为,则继续250@Gryphius-我不完全确定?我会假设它是域的连接细节,在你做EHLO之前,你会打印出来,所以你应该看到它。。。?您还可以通过简单地将telnettig发送到目标主机进行测试,并检查横幅是否有多行。我这样做了,它通过了ehlo命令,但是它会忽略my mail from:、rcpt to:、和data,直接转到quit命令。当我回显$res时,我收到的信息是:220 net-isp.net ESMTP MailCleaner(社区版2012.5)周二,2013年11月12日15:45:13+0000 250-net-isp.net你好host217-45-150-185.in-addr.btopenworld.com[217.45.150.185]250-SIZE 52428800 250-8BITMIME 250-pipelling 250-pipelling 250-pipelling 250-AUTH普通登录250 startls抱歉,我不再帮你了。您试图使用一个完全损坏的PHP脚本从一个被列入黑名单的IP向第三方服务器发送邮件,该脚本基本上是从PHP fsockopen手册页面上一条11年前的评论中复制的。。。请先熟悉SMTP协议和您尝试使用的代码,然后再询问。
fputs($connection, "EHLO $mydomain\r\n");