XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
MyMailer.class.php
1<?php
12
13if (!defined('XOOPS_ROOT_PATH')) {
14 exit();
15}
16
17if (!defined('LEGACY_MAIL_LANG')) {
18 define('LEGACY_MAIL_LANG', _LANGCODE);
19 define('LEGACY_MAIL_CHAR', _CHARSET);
20 define('LEGACY_MAIL_ENCO', '7bit');
21}
22
23//Import PHPMailer classes into the global namespace
24use PHPMailer\PHPMailer\PHPMailer;
25use PHPMailer\PHPMailer\SMTP;
26use PHPMailer\PHPMailer\Exception;
27
28
29class My_Mailer extends PHPMailer
30{
31 public $mConvertLocal = null;
32
33 public function __construct()
34 {
35 $this->mConvertLocal = new XCube_Delegate();
36 $this->mConvertLocal->register('Legacy_Mailer.ConvertLocal');
37 self::$LE ="\n";
38 $this->prepare();
39 }
40
41 public function prepare()
42 {
43 $root = XCube_Root::getSingleton();
44 $handler = xoops_gethandler('config');
45 $xoopsMailerConfig = $handler->getConfigsByCat(XOOPS_CONF_MAILER);
46 $this->reset();
47
48 if ('' === $xoopsMailerConfig['from']) {
49 $this->From = $root->mContext->mXoopsConfig['adminmail'];
50 } else {
51 $this->From = $xoopsMailerConfig['from'];
52 }
53
54 $this->Sender = $root->mContext->mXoopsConfig['adminmail'];
55 $this->SetLanguage(LEGACY_MAIL_LANG, XOOPS_ROOT_PATH.'/class/mail/phpmailer/language/');
56 $this->CharSet = LEGACY_MAIL_CHAR;
57 $this->Encoding = LEGACY_MAIL_ENCO;
58
59 switch ($xoopsMailerConfig['mailmethod']) {
60 case 'smtpauth':
61 $this->IsSMTP();
62 $this->SMTPAuth = true;
63 $this->Host = implode(';', $xoopsMailerConfig['smtphost']);
64 $this->Username = $xoopsMailerConfig['smtpuser'];
65 $this->Password = $xoopsMailerConfig['smtppass'];
66 break;
67
68 case 'smtp':
69 $this->IsSMTP();
70 $this->SMTPAuth = false;
71 $this->Host = implode(';', $xoopsMailerConfig['smtphost']);
72 break;
73
74 case 'sendmail':
75 $this->IsSendmail();
76 $this->Sendmail = $xoopsMailerConfig['sendmailpath'];
77 break;
78 }
79
80 return true;
81 }
82
83 public function setFromEmail($text)
84 {
85 $this->From = $text;
86 }
87
88 public function setFromName($text)
89 {
90 $this->FromName = $this->convertLocal($this->SecureHeader($text), true);
91 }
92
93 public function setSubject($text)
94 {
95 $this->Subject = $text;
96 }
97
98 public function setBody($text)
99 {
100 $search = ["\r\n", "\r", "\n"];
101 $replace = ["\n", "\n", self::$LE]; // PHPMailer 6.x.x
102 $text = str_replace($search, $replace, $text);
103 $this->Body = $this->convertLocal($text);
104 }
105
106 public function setToEmails($email)
107 {
108 $this->AddAddress($email, '');
109 }
110
111 public function setTo($add, $name = '')
112 {
113 $this->AddAddress($add, $name);
114 }
115
116 public function reset()
117 {
118 $this->ClearAllRecipients();
119 $this->Body = '';
120 $this->Subject = '';
121 }
122
123 public function send()
124 {
125 parent::send();
126 }
127
128 public function EncodeHeader($str, $position = 'text')
129 {
130 if ('text' === $position) {
131 return $this->convertLocal($str, true);
132 } else {
133 return parent::EncodeHeader($str, $position);
134 }
135 }
136
137 private function convertLocal($text, $mime = false)
138 {
139 if (_LANGCODE === 'ja') {
140 $text = $this->_Japanese_convLocal($text, $mime);
141 } else {
142 $this->mConvertLocal->call(new XCube_Ref($text), $mime);
143 }
144 return $text;
145 }
146
147 private function _Japanese_convLocal($text, $mime)
148 {
149 if ($mime) {
150 $text = mb_encode_mimeheader($text, LEGACY_MAIL_CHAR, 'B', $this->LE);
151 } else {
152 $text = mb_convert_encoding($text, 'JIS', _CHARSET);
153 }
154 return $text;
155 }
156}
[Final] Used for the simple mechanism for common delegation in XCube.