-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmail.php
90 lines (79 loc) · 3.26 KB
/
mail.php
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
90
<?php
require_once 'phpmailer/class.phpmailer.php';
class SendMail {
private static $instance;
public static function get_instance() {
if(!self::$instance) {
self::$instance = new SendMail();
}
return self::$instance;
}
public function send($file) {
if(empty($file) || !file_exists($file)) {
echo "File can't be find";
return '';
}
//defaults to using php "mail()"; the true param means it will throw exceptions on errors, which we need to catch
$mail = new PHPMailer(true);
try {
$mail->CharSet = "UTF-8";
$mail->IsSMTP();
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
//$mail->SMTPSecure = "ssl";
$mail->Host = "smtp.anjuke.com";
$mail->Port = 25;
$mail->Username = "[email protected]";
$mail->Password = "xxxx";
$mail->AddReplyTo('[email protected]', 'First Last');
$mail->AddAddress('[email protected]', 'Feng');
$mail->SetFrom('[email protected]', 'Me');
$mail->Subject = 'FT chinese';
$mail->AltBody = 'Auto Sendmail with attachment';
$mail->MsgHTML('From Phpmailer');
$mail->AddAttachment($file); // attachment
$mail->Send();
echo "Message Sent OK<p></p>\n";
} catch (phpmailerException $e) {
echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
echo $e->getMessage(); //Boring error messages from anything else!
}
}
public function send_mail($address,$title = "Nothing",$content = "Nothing") {
if(empty($address)) {
echo "Please give your mail address";
return '';
}
//defaults to using php "mail()"; the true param means it will throw exceptions on errors, which we need to catch
$mail = new PHPMailer(true);
try {
$mail->CharSet = "UTF-8";
$mail->IsSMTP();
$mail->SMTPDebug = 1;
$mail->SMTPSecure = "ssl";
$mail->SMTPAuth = true; // 启用 SMTP 验证功能
$mail->Host = "smtp.126.com";
$mail->Port = 994; // SMTP服务器的端口号
$mail->Username = "sogoquick"; // SMTP服务器用户名
$mail->Password = "guilin123"; // SMTP服务器密码
$mail->SetFrom('[email protected]', 'coldarmy');
$mail->AddReplyTo("[email protected]","coldarmy");
$mail->Subject = $title;
$mail->AltBody = $content; // optional, comment out and test
$mail->MsgHTML($content);
$mail->AddAddress($address, "Feng");
$mail->Send();
echo "Message Sent OK<p></p>\n";
} catch (phpmailerException $e) {
echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
echo $e->getMessage(); //Boring error messages from anything else!
}
}
private function __clone(){
}
private function __construct() {
}
}
?>