sinykk 发表于 2013-1-25 03:39:14

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";}}?>
页: [1]
查看完整版本: PHPMailer_v5.1 使用