Send.class.php
2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
require_once dirname(__FILE__).'/config/config.php';
class Util_Mail_Send
{
/**
* @var object
*/
private static $mMailer = null;
/**
* 发送邮件消息
*
* @param string $toAddress
* @param string $subject
* @param string $content
* @param string $fromAlias
* @return boolean
*/
public static function send($toAddress = '', $subject, $content, $fromAlias = 'yoho')
{
self::init();
$emailMatch = "/^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6}$/i";
//正确的邮箱
$rightEmail = '';
if(preg_match($emailMatch,$toAddress) && strlen($subject))
{
$rightEmail = $toAddress;
}
else
{
return false;
}
//收件人地址,格式是AddAddress("收件人email","收件人姓名")
self::$mMailer->AddAddress($rightEmail,'');
//发送者别名
self::$mMailer->FromName = $fromAlias;
//邮件标题,设置标题编码
self::$mMailer->Subject = "=?UTF-8?B?".base64_encode($subject) ."?=";
//邮件内容
self::$mMailer->Body = $content;
//邮件发送成功
if(self::$mMailer->Send())
{
return true;
}
else
{
return false;
}
}
/**
* 添加附件
*
* @param string $filename
*/
public static function addAttachment($filename)
{
if(file_exists($fileName) && strlen($filename))
{
//添加附件
self::$mMailer->AddAttachment($filename);
}
}
/**
* 初始化
*/
private static function init()
{
self::$mMailer = new Util_Mail_Phpmailer();
// 邮局用户名(请填写完整的email地址)
self::$mMailer->Username = MAILLOGINNAME;
//邮局密码
self::$mMailer->Password = MAILLOGINPASSWORD;
//邮件发送者email地址
self::$mMailer->From = MAILLOGINNAME;
//使用SMTP方式发送
self::$mMailer->mMailer->IsSMTP();
//企业邮局域名
self::$mMailer->Host = MAILHOST;
// 启用SMTP验证功能
self::$mMailer->SMTPAuth = true;
//设置邮件编码
self::$mMailer->CharSet = 'utf-8';
//是否使用HTML格式
self::$mMailer->IsHTML(true);
}
}