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();
}
}
Asked
Active
Viewed 74 times
0
-
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 Answers
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
-
but smtp or hostname is connected and i want to show that. but my code alwys display ip not connected when its working – sannrash Jul 01 '15 at 06:20
-
As said: `imap_open()` reports that the connection failed if `$mbox` resolves to `FALSE` in the condition. Why do you think it succeeded? How do you tell? – arkascha Jul 01 '15 at 06:21
-
-
Sorry, no, I cannot give you a solution, since I do not see an issue here to be solved. I cannot say why your connection attempts fail. – arkascha Jul 01 '15 at 06:23
-
-
Then maybe you ask the wrong question? you did not answer to my question two comments above... – arkascha Jul 01 '15 at 06:24
-
-
-
Still no answer to my question above. Instead you through code at me. Sorry, I am out. – arkascha Jul 01 '15 at 06:29
-
-