tags:

views:

35

answers:

2

Hi.

Simply what the title says. Want to know how to check if the connection is working and if not, what is the error. Btw the SMTP server is exchange 2007.

+2  A: 

If you want to know if you can access the SMTP server from wherever you are running PHP, then you just need to connect to it on the appropriate port (default 25) and see if you get back a "220" code in the result.

$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) ;
Fanis
A: 

Since this is most likely related to your other question: http://stackoverflow.com/questions/3660774/configure-mail-server-to-work-with-php, I'll put the answer here too:

You're using the PEAR Mail package. The send() method returns TRUE on success, or a PEAR_Error object otherwise, which will contain details of the failure. Most likely you'd want $PEAR_Error::message. Full details here: http://stackoverflow.com/questions/3660774/configure-mail-server-to-work-with-php

Marc B