如何检查smtp服务器是否工作或不使用PHP

如何检查smtp服务器是否工作或不使用PHP

问题描述:

我想检查我的网站smtp是否停机或使用php。我尝试使用fsockopen连接到服务器上的端口25,然后在运行smtp服务时返回true。这是测试smtp或ftp是否使用php脚本运行的最佳方法。

i want to check whether my websites smtp is down or up using php . I tried to connect to port 25 on my server using fsockopen, then it returns true when there is smtp service running. Which is the best method to test whether smtp or ftp running using php script.

您正在讨论一个smtp服务器,所以您必须启用pear框架。我有一个链接 http://www.authsmtp.com/php-pear-mail/一个>可以帮助。
或者你可以这样做:

you are talking of a smtp server , so you must have the pear framework enabled. I had a link http://www.authsmtp.com/php-pear-mail/ which can be of help. or you can do this:

$f = fsockopen('smtp host', 25) ;
if ($f !== false) {
    $res = fread($f, 1024) ;
    if (strlen($res) > 0 && strpos($res, '220') === 0) {
        echo "Success!" ;
    }
    else {
        echo "Error: " . $res ;
    }
}
fclose($f) ;