验证页面的返回状态(实例讲解)(2)

if($end<$start)
            {
                $end=$start;
            }
            $sTime=date("Y/m/d H:m:s");
            echo "开始时间".$sTime."<br/>";
            echo "检测结果<br />";
            for($i=$start;$i<=$end;$i++)
            {
                $url=ResetUrl($UrlArr[$i]);
                $state=GetStatusCode($url);
                echo "&nbsp;&nbsp;".$state ."&nbsp;=>&nbsp;<a href='http://".$url."' target='_blank'>".$url."<a>";
                if($state!="200")
                {
                    echo " <span>本条访问出错!</span><br/>";
                    send_http_status($state);

//发邮件
                    require("Mail.php");
                    $MailPara["Subject"]="网站监控结果";
                    $MailPara["Body"]="错误信息:状态-><span>".$state."</span><br/>地址:".$url;
                    SendResultMail($MailPara);

break;
                }
                echo "<br/>";
            }
            $eTime=date("Y/m/d H:m:s");

echo "结束时间".$eTime."<br/>";
        }

}
    ShowStateInfo($UrlArr,$MailPara);
?>


2.邮件

复制代码 代码如下:


function SendResultMail($MailPara)
    {
        require("phpmailer/class.phpmailer.php");

$mail = new PHPMailer();
        $mail->CharSet = $MailPara["CharSet"];
        $mail->IsSMTP();
        $mail->Host = $MailPara["Host"];
        $mail->Port = $MailPara["Port"];

$mail->SMTPAuth = true;

$mail->Username = $MailPara["FromMail"];
        $mail->Password = $MailPara["FromMailPassword"];
        $mail->From = $MailPara["FromMail"];
        $mail->FromName = $MailPara["FromMailName"];

foreach($MailPara["To"] as $toMail)
        {
            $mail->AddAddress($toMail["ToMail"], $toMail["ToMailName"]);
        }

$mail->Subject = $MailPara["Subject"];
        $mail->Body = $MailPara["Body"];
        $mail->AltBody = $MailPara["AltBody"];

if(!$mail->Send())
        {
            echo "邮件发送失败. <p>";
            echo "错误原因: " . $mail->ErrorInfo ."<br/>";
            exit;
        }

echo "邮件发送成功<br/>";
    }


3.配置文件

复制代码 代码如下:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/2436312a11ae31cd61199fbafe501602.html