如何检查smtp连接或不使用PHP。我是php的新手

时间:2015-07-01 06:07:21

标签: php smtp server

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();
    }
}

1 个答案:

答案 0 :(得分:0)

如果您的问题确实是&#34;如何检查smtp是否连接&#34;,那么答案是:你做得很好!

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

您可以使条件更具可读性和显性:if (FALSE === $mbox)