如何通过PHP检查我的脚本是否连接到SMTP服务器 [英] How to check, by PHP, if my script is connecting to SMTP server

查看:139
本文介绍了如何通过PHP检查我的脚本是否连接到SMTP服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

就是标题所说的. 想知道如何检查连接是否正常,如果不正常,那是什么错误. 顺便说一句,SMTP服务器是Exchange 2007.

Simply what the title says. Want to know how to check if the connection is working and if not, what is the error. Btw the SMTP server is exchange 2007.

推荐答案

如果您想知道是否可以从运行PHP的任何地方访问SMTP服务器,则只需在适当的端口上连接它即可(默认25),看看结果中是否返回了"220"代码.

If you want to know if you can access the SMTP server from wherever you are running PHP, then you just need to connect to it on the appropriate port (default 25) and see if you get back a "220" code in the result.

$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) ;

这篇关于如何通过PHP检查我的脚本是否连接到SMTP服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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