how to check smtp server is working or not using php

11,164

you are talking of a smtp server , so you must have the pear framework enabled. I had a link http://www.authsmtp.com/php-pear-mail/ which can be of help. or you can do this:

$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) ; 
Share:
11,164

Related videos on Youtube

user2307392
Author by

user2307392

Updated on September 15, 2022

Comments

  • user2307392
    user2307392 over 1 year

    i want to check whether my websites smtp is down or up using php . I tried to connect to port 25 on my server using fsockopen, then it returns true when there is smtp service running. Which is the best method to test whether smtp or ftp running using php script.