如何在这个php检查脚本中添加电子邮件功能


How to add email function to this php checking script?

如何添加电子邮件功能发送,如果端口不响应(false)下面的脚本?

<?php
function test_port($host,$port=80,$timeout=6)
{
        $fsock = fsockopen($host, $port, $errno, $errstr, $timeout);
        if ( ! $fsock )
        {
                return FALSE;
        }
        else
        {
                return TRUE;
        }
}
/* check our website http://www.example.com is up and running (port 80) and timeout after 20 seconds */
$ok = test_port('IP/website',80,20);
?>

最简单的方法是将return FALSE;替换为对PHP mail函数的适当调用

编辑:这解决了mail()问题,但请注意,fsockopen 可能不是检测主机是否启动的正确方法。