如何检查smtp服务器是否工作或不使用PHP [英] how to check smtp server is working or not using php

查看:269
本文介绍了如何检查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) ; 

这篇关于如何检查smtp服务器是否工作或不使用PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆