首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网络技术 > 网络基础 >

PHPMailer_v5.1 施用

2012-10-29 
PHPMailer_v5.1 使用今天写的一个简单的检查服务器数据库连接报警发邮件功能??php/* * email 报警,主要检

PHPMailer_v5.1 使用

今天写的一个简单的检查服务器数据库连接报警发邮件功能

?

<?php/* * email 报警,主要检查服务器数据库是否还能正常连接 */ require("../common/config.php");include("../common/class.phpmailer.php");include("../common/class.smtp.php"); // note, this is optional - gets called from main class if not already loaded$conn = mysql_connect($_SC['dbhost'],$_SC['dbuser'],$_SC['dbpw']); if(!$conn){ sendAlarmEmail(); die("连接数据库失败"); exit(); }else{ echo '数据库连接成功'; }function sendAlarmEmail(){$mail             = new PHPMailer();//$body             = $mail->getFile('a.htm');//$body             = eregi_replace("[\]",'',$body);$mail->IsSMTP();$mail->SMTPAuth   = true;                  // enable SMTP authentication//$mail->SMTPSecure = "ssl";                 // sets the prefix to the servier$mail->Host       = "smtp.qq.com";      // sets GMAIL as the SMTP server$mail->Port       = 25;                   // set the SMTP port$mail->Username   = "827798208@qq.com";  // GMAIL username$mail->Password   = "******";            // GMAIL password$mail->From       = "827798208@qq.com";$mail->FromName   = "sinykk";$mail->Subject    = "company server mysql caught error";//$mail->AltBody    = "This is the body when user views in plain text format附加内容"; //Text Body$mail->WordWrap   = 50; // set word wrap//$mail->MsgHTML($body);$mail->Body="company server mysql caught error ip 122...";$mail->AddReplyTo("sinykk@yeah.net","sinykk");//$mail->AddAttachment("/path/to/file.zip");             // attachment//$mail->AddAttachment("/path/to/image.jpg", "new.jpg"); // attachment$mail->AddAddress("158688466XX@139.com","sinykk_mobile");$mail->IsHTML(false); // send as HTMLif(!$mail->Send()) {  echo "Mailer Error: " . $mail->ErrorInfo;} else {  echo "Message has been sent";}}?>
?

热点排行