我在 Linux 服务器上有一个 PHP 脚本,需要确定电子邮件地址是真实的还是虚假的。
我正在尝试为此使用 telnet,从期望脚本启动,但它不起作用。
PHP 脚本的用法是:
$retVal = shell_exec( "./atelnet.sh mailserver.net fake@example.com" ) ;
任何帮助将不胜感激,或者完全是更好的方法。
谢谢你。
这是我到目前为止所拥有的:
#!/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 ???
编辑:
我在我的 PHP 套接字代码下面添加,这似乎不起作用:
$smtp_server = fsockopen( $mx_hostname, 25, $errno, $errstr, 30 ) ;
$ret1 = fwrite( $smtp_server, "helo hi\r\n" ) ;
$ret2 = fwrite( $smtp_server, "mail from: <a@b.org>\r\n" ) ;
$ret3 = fwrite( $smtp_server, "rcpt to: <" . $unk_email_address. ">\r\n" ) ;
对此代码的任何想法也将受到欢迎。
谢谢你。