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

时间: 2024-10-13 02:10:32

PHPMailer_v5.1 使用[转]的相关文章

我的PHPMailer_v5.1 使用

<?php /** * Simple example script using PHPMailer with exceptions enabled * @package phpmailer * @version $Id$ */ require_once'/class.phpmailer.php'; require_once'/class.smtp.php'; try { $mail = new PHPMailer(true); //New instance, with exceptions en

POP3协议分析邮箱自动激活用户

使用POP3协议分析邮箱自动激活用户 2015-03-28 Lover雪儿 前几天,我们实现了,用户PHP模拟邮件激活注册用户, 地址:http://www.cnblogs.com/lihaiyan/p/4359927.html ,但是有的时候,往往是需要注册用户自己手动的向服务器的邮箱进行发送一封邮件,然后服务器通过分析邮箱的发件人,从而匹配自动的激活用户账号. 上class.pop3.php 邮件发送人分析php源代码: 1 <?php 2 3 //用户往[email protected]邮