如何使用php检查smtp是否连接.我是php的新手


how to check smtp connected or not using php. i am newbie to php

include("../confi.php");
require 'PHPMailerAutoload.php';
//echo $select_smtp="SELECT * FROM `smtp_connection`";
$select_smtp=mysql_query("SELECT * FROM `smtp_connection` WHERE `status`=1",$database);
while($result_select = mysql_fetch_array($select_smtp))
{
    $hostname= $result_select['host_name'];
    $username= $result_select['user_name'];
    $userpass= $result_select['user_pass'];
    $status= $result_select['status'];
    $time= $result_select['check_time'];
    $port="25/pop3";
    $mbox = imap_open( "{".$hostname.":".$port."/novalidate-cert}" , $username, $userpass);
    if ($mbox) {
        echo "connected";
        imap_close($mbox);
    } else {
        echo "not connected :<br>" . imap_last_error();
    }
}

如果你的问题真的是"如何检查smtp是否连接",那么答案是:你做得很好!

imap_open()的文档明确指出,函数在失败时返回资源或FALSE。因此,您的条件if ($mbox)可靠地检查连接是否成功。

您可以使条件更加可读和明确:if (FALSE === $mbox)

相关文章: