dongyutan1703 2013-03-22 23:49
浏览 221

Linux服务器上的PHP - 如何验证该电子邮件地址是否真实

I have a PHP script on a Linux server that needs to determine whether an email address is real or fake.

I'm trying to use telnet for this, launched from an expect script, but it's not working.

The PHP script usage would be:

$retVal = shell_exec( "./atelnet.sh mailserver.net fake@example.com" ) ;

Any help would be appreciated, or a better approach altogether.

Thank you.

Here's what I have so far:

#!/usr/bin/expect
#
# name: atelnet.sh
# usage from php: 
# $retVal = shell_exec( "./atelnet.sh mailserver.net fake@example.com" ) ;
#
# if goes wrong, the script will timeout in 20 seconds
set timeout 20

# first argument assigned to the variable "server"
set server [lindex $argv 0]

# second argument assigned to the variable "emailaddress"
set emailaddress [lindex $argv 1]

# spawn telnet and connect to variable "server" on port 25
spawn telnet $server 25

# script expects "220 ..." telnet from server, telnet login ok response
# actual response looks like: 
# "220 mx.server.com ESMTP ni10si2925797obc.73 - gsmtp"
# or
# "220-host.server.com ESMTP Fri, 22 Mar 2013 01:48:03 -0000"
expect "220"

# script sends initial handshake greeting
send "HELO"

# script expects "250 ..." telnet from server, at-your-service ok response
# actual response looks like: 
# "250 mx.server.com at your service"
# or
# "250 host.server.com Hello host.server.com [111.222.333.444]"
expect "250"

# script sends from: email address (any address is fine)
send "mail from:<a@b.com>"

# script expects "250 ..." telnet from server, ok acknowledgement of from:email
# actual response looks like: 
# "250 2.1.0 OK v16si1294229qct.125 - gsmtp"
# or
# "250 OK"
expect "250"

# script sends query to the email address being tested
# PHP string cat syntax doesn't work !!!
# HOW ???
send "rcpt to:<" . $emailaddress . ">"

# script expects one of these:
# fake: "550-5.1.1 The email account that you tried to reach does not exist."
# or
# true: "250 Accepted"

# log server's response to file. HOW ???

EDIT:

I'm adding below my PHP socket code, which doesn't seem to work:

$smtp_server = fsockopen( $mx_hostname, 25, $errno, $errstr, 30 ) ;
$ret1 = fwrite( $smtp_server, "helo hi
" ) ;
$ret2 = fwrite( $smtp_server, "mail from: <a@b.org>
" ) ;
$ret3 = fwrite( $smtp_server, "rcpt to: <" . $unk_email_address. ">
" ) ;

Any ideas on this code would be welcomed as well.

Thank you.

  • 写回答

3条回答 默认 最新

  • dongyu9850 2013-03-22 23:55
    关注

    There is no point trying to invent wheel.

    Check for example: Zend_Validate_EmailAddress

    You can even validate hostname and mx record

    $validator = new Zend_Validate_EmailAddress(
        array(
            'allow' => Zend_Validate_Hostname::ALLOW_DNS,
            'mx'    => true
        )
    );
    

    and by validating existing domain and email address format I would say it should be enough.

    评论

报告相同问题?

悬赏问题

  • ¥20 蓝牙耳机怎么查看日志
  • ¥15 R语言 拟时序分析降维图如何减少分支
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统