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 HTML
	
	if(!$mail->Send()) {
	  echo "Mailer Error: " . $mail->ErrorInfo;
	} else {
	  echo "Message has been sent";
	}
}

?>
 
class PHPMailer { ///////////////////////////////////////////////// // PROPERTIES, PUBLIC ///////////////////////////////////////////////// /** * Email priority (1 = High, 3 = Normal, 5 = low). * @var int */ public $Priority = 3; /** * Sets the CharSet of the message. * @var string */ public $CharSet = 'iso-8859-1'; /** * Sets the Content-type of the message. * @var string */ public $ContentType = 'text/plain'; /** * Sets the Encoding of the message. Options for this are * "8bit", "7bit", "binary", "base64", and "quoted-printable". * @var string */ public $Encoding = '8bit'; /** * Holds the most recent mailer error message. * @var string */ public $ErrorInfo = ''; /** * Sets the From email address for the message. * @var string */ public $From = 'root@localhost'; /** * Sets the From name of the message. * @var string */ public $FromName = 'Root User'; /** * Sets the Sender email (Return-Path) of the message. If not empty, * will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode. * @var string */ public $Sender = ''; /** * Sets the Subject of the message. * @var string */ public $Subject = ''; /** * Sets the Body of the message. This can be either an HTML or text body. * If HTML then run IsHTML(true). * @var string */ public $Body = ''; /** * Sets the text-only body of the message. This automatically sets the * email to multipart/alternative. This body can be read by mail * clients that do not have HTML email capability such as mutt. Clients * that can read HTML will view the normal Body. * @var string */ public $AltBody = ''; /** * Sets word wrapping on the body of the message to a given number of * characters. * @var int */ public $WordWrap = 0; /** * Method to send mail: ("mail", "sendmail", or "smtp"). * @var string */ public $Mailer = 'mail'; /** * Sets the path of the sendmail program. * @var string */ public $Sendmail = '/usr/sbin/sendmail'; /** * Path to PHPMailer plugins. Useful if the SMTP class * is in a different directory than the PHP include path. * @var string */ public $PluginDir = ''; /** * Sets the email address that a reading confirmation will be sent. * @var string */ 一个可以收发邮件的工具类
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值