<?php
/**
* 邮件
* http://www.heqee.com
*/
class lib_mail
{
private static $config;
private static $from_email;
private static $from_name;
private static $charset;
private static $smtp_server;
private static $smtp_port;
private static $smtp_ssl;
private static $smtp_auth;
private static $smtp_user;
private static $smtp_pwd;
/**
* 初始化
*
* @return void
*/
public static function init()
{
global $cfg;
self::$config = $cfg;
self::$from_email = self::$config['from_email'];
self::$from_name = self::$config['from_name'];
self::$charset = self::$config['charset'];
}
public static function smtp_init()
{
self::$smtp_server = self::$config['smtp_server'];
self::$smtp_port = self::$config['smtp_port'];
self::$smtp_ssl = self::$config['smtp_ssl'];
self::$smtp_auth = self::$config['smtp_auth'];
self::$smtp_user = self::$config['smtp_user'];
self::$smtp_pwd = self::$config['smtp_pwd'];
}
/**
* 发送邮件
*
* @param string $to
* @param string $to_name
* @param string $subject
* @param string $body
* @param string $mailtype
* @return boolean
*/
public static function send($to, $to_name, $subject, $body, $mailtype = 'txt')
{
self::init();
$send_type = self::$config['send_type'];
$mail = new PHPMailer();
$mail->SMTPDebug = false;
// 发送方式
if ($send_type == 'smtp')
{
self::smtp_init();
$mail->IsSMTP();
$mail->Host = self::$smtp_server;
$mail->Port = self::$smtp_port;
$mail->SmtpSsl = self::$smtp_ssl;// SSL 连接
if (self::$smtp_auth)
{
$mail->SMTPAuth = true;
$mail->Username = self::$smtp_user;
$mail->Password = self::$smtp_pwd;
}
else
{
$mail->SMTPAuth = false;
}
}
elseif ($send_type == 'mail')
{
$mail->IsMail();
}
// 发件人邮箱
$mail->From = self::$from_email;
// 发件人名称
if (self::$from_name != '')
{
$mail->FromName = self::$from_name;
}
// 收件人邮箱和姓名
$mail->AddAddress($to, $to_name);
// 邮件编码
$mail->CharSet = self::$charset;
// 邮件编码方式
$mail->Encoding = "base64";
// 邮件格式类型
if ($mailtype == 'txt')
{
$mail->IsHTML(false);
}
elseif($mailtype == 'html')
{
$mail->IsHTML(true);
$mail->AltBody ="text/html";
}
$mail->Subject = $subject;// 邮件主题
$mail->Body = $body;// 邮件内容
return (!$mail->Send()) ? false : true;
}
}
// PHPMAILER 邮件发送类
// PHPMAILER 语言包
$PHPMAILER_LANG = array();
$PHPMAILER_LANG["provide_address"] = 'You must provide at least one ' . 'recipient email address.';
$PHPMAILER_LANG["mailer_not_supported"] = ' mailer is not supported.';
$PHPMAILER_LANG["execute"] = 'Could not execute: ';
$PHPMAILER_LANG["instantiate"] = 'Could not instantiate mail function.';
$PHPMAILER_LANG["authenticate"] = 'SMTP Error: Could not authenticate.';
$PHPMAILER_LANG["from_failed"] = 'The following From address failed: ';
$PHPMAILER_LANG["recipients_failed"] = 'SMTP Error: The following ' . 'recipients failed: ';
$PHPMAILER_LANG["data_not_accepted"] = 'SMTP Error: Data not accepted.';
$PHPMAILER_LANG["connect_host"] = 'SMTP Error: Could not connect to SMTP host.';
$PHPMAILER_LANG["file_access"] = 'Could not access file: ';
$PHPMAILER_LANG["file_open"] = 'File Error: Could not open file: ';
$PHPMAILER_LANG["encoding"] = 'Unknown encoding: ';
////////////////////////////////////////////////////
// PHPMailer - PHP email class
//
// Class for sending email using either
// sendmail, PHP mail(), or SMTP. Methods are
// based upon the standard AspEmail(tm) classes.
//
// Copyright (C) 2001 - 2003 Brent R. Matzelle
//
// License: LGPL, see LICENSE
////////////////////////////////////////////////////
/**
* PHPMailer - PHP email transport class
* @package PHPMailer
* @author Brent R. Matzelle
* @copyright 2001 - 2003 Brent R. Matzelle
*/
class PHPMailer
{
/////////////////////////////////////////////////
// PUBLIC VARIABLES
/////////////////////////////////////////////////
/**
* 电子邮件优先级 Email priority (1 = High, 3 = Normal, 5 = low).
* @var int
*/
var $Priority = 1;
// 是否使用ssl 连接
var $SmtpSsl =0;
/**
* Sets the CharSet of the message.
* @var string
*/
var $CharSet = "utf-8";
/**
* Sets the Content-type of the message.
* @var string
*/
var $ContentType = "text/plain";
/**
* Sets the Encoding of the message. Options for this are "8bit",
* "7bit", "binary", "base64", and "quoted-printable".
* @var string
*/
var $Encoding = "base64";
/**
* Holds the most recent mailer error message.
* @var string
*/
var $ErrorInfo = "";
/**
* Sets the From email address for the message.
* @var string
*/
var $From = "root@localhost";
/**
* Sets the From name of the message.
* @var string
*/
var $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
*/
var $Sender = "";
/**
* Sets the Subject of the message.
* @var string
*/
var $Subject = "";
/**
* Sets the Body of the message. This can be either an HTML or text body.
* If HTML then run IsHTML(true).
* @var string
*/
var $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
*/
var $AltBody = "";
/**
* Sets word wrapping on the body of the message to a given number of
* characters.
* @var int
*/
var $WordWrap = 0;
/**
* Method to send mail: ("mail", "sendmail", or "smtp").
* @var string
*/
var $Mailer = "mail";
/**
* Sets the path of the sendmail program.
* @var string
*/
var $Sendmail = "/usr/sbin/sendmail";
/**
* Path to PHPMailer plugins. This is now only useful if the SMTP class
* is in a different directory than the PHP include path.
* @var string
*/
var $PluginDir = "";
/**
* Holds PHPMailer version.
* @var string
*/
var $Version = "1.73";
/**
* Sets the email address that a reading confirmation will be sent.
* @var string
*/
var $ConfirmReadingTo = "";
/**
* Sets the hostname to use in Message-Id and Received headers
* and as default HELO string. If empty, the value returned
* by SERVER_NAME is used or 'localhost.localdomain'.
* @var string
*/
var $Hostname = "";
/////////////////////////////////////////////////
// SMTP VARIABLES
/////////////////////////////////////////////////
/**
* Sets the SMTP hosts. All hosts must be separated by a
* semicolon. You can also specify a different port
* for each host by using this format: [hostname:port]
* (e.g. "smtp1.example.com:25;smtp2.example.com").
* Hosts will be tried in order.
* @var string
*/
var $Host = "localhost";
/**
* Sets the default SMTP server port.
* @var int
*/
var $Port = 25;
/**
* Sets the SMTP HELO of the message (Default is $Hostname).
* @var string
*/
var $Helo = "";
/**
* Sets SMTP authentication. Utilizes the Username and Password variables.
* @var bool
*/
var $SMTPAuth = false;
/**
* Sets SMTP username.
* @var string
*/
var $Username = "";
/**
* Sets SMTP password.
* @var string
*/
var $Password = "";
/**
* Sets the SMTP server timeout in seconds. This function will not
* work with the win32 version.
* @var int
*/
var $Timeout = 10;
/**
* Sets SMTP class debugging on or off.
* @var bool
*/
var $SMTPDebug = false;
/**
* Prevents the SMTP connection from being closed after each mail
* sending. I