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   = "[email protected]";  // GMAIL username  
    $mail->Password   = "******";            // GMAIL password  
      
    $mail->From       = "[email protected]";  
    $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("[email protected]","sinykk");  
      
    //$mail->AddAttachment("/path/to/file.zip");             // attachment  
    //$mail->AddAttachment("/path/to/image.jpg", "new.jpg"); // attachment  
      
      
    $mail->AddAddress("[email protected]","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)