码迷,mamicode.com
首页 > Web开发 > 详细

PHPMailer_v5.1 使用[转]

时间:2015-01-25 22:20:49      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:

<?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";  
    }  
}  
  
?>  

 感谢! 来自:http://sinykk.iteye.com/blog/990670

PHPMailer_v5.1 使用[转]

标签:

原文地址:http://www.cnblogs.com/perseverancevictory/p/4249046.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!