0
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();
    }
}
arkascha
  • 41,620
  • 7
  • 58
  • 90
sannrash
  • 3
  • 4
  • possible duplicate of [Failed to connect to mailserver at "localhost" port 25](http://stackoverflow.com/questions/4532486/failed-to-connect-to-mailserver-at-localhost-port-25) – Vidya Sagar Jul 01 '15 at 06:14
  • i cant find actual error. all smtp server are connected but its not shown in code. output is as follow: IP Not connected : COMPUTER-NAME.npet.in ESMTP MailEnable Service, Version: 8.60-- ready at 06/30/15 22:25:54 @Sagar – sannrash Jul 01 '15 at 06:15
  • can sm1 plz post appropriate code. – sannrash Jul 01 '15 at 06:16

1 Answers1

0

If your question really is "how to check smtp connected or not", then the answer is: you did great!

The documentation of imap_open() clearly states that the function returns either a resource or FALSE in case of a failure. So your conditional if ($mbox) reliably checks if the connection was successful.

You could make the condition more readable and explicit though: if (FALSE === $mbox)

arkascha
  • 41,620
  • 7
  • 58
  • 90