PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 4.14.1
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v4.14.1
5.12.0 5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / app / core / Mail / Transport.php
matomo / app / core / Mail Last commit date
EmailStyles.php 5 years ago Transport.php 3 years ago
Transport.php
158 lines
1 <?php
2 /**
3 * Matomo - free/libre analytics platform
4 *
5 * @link https://matomo.org
6 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
7 *
8 */
9
10 namespace Piwik\Mail;
11
12 use PHPMailer\PHPMailer\PHPMailer;
13 use PHPMailer\PHPMailer\SMTP;
14 use Piwik\Config;
15 use Piwik\Container\StaticContainer;
16 use Piwik\Mail;
17 use Piwik\Piwik;
18
19 class Transport
20 {
21 /**
22 * Sends the given mail
23 *
24 * @param Mail $mail
25 * @return bool
26 * @throws \DI\NotFoundException
27 * @throws \PHPMailer\PHPMailer\Exception
28 */
29 public function send(Mail $mail)
30 {
31 $phpMailer = new PHPMailer(true);
32
33 //check self-signed config in mail
34 $phpMailer->SMTPOptions = [
35 'ssl' => [
36 'verify_peer' => (int)Config::getInstance()->mail['ssl_verify_peer'],
37 'verify_peer_name' => (int)Config::getInstance()->mail['ssl_verify_peer_name'],
38 'allow_self_signed' => Config::getInstance()->mail['ssl_disallow_self_signed'] == "1" ? 0 : 1,
39 ],
40 ];
41
42 PHPMailer::$validator = 'pcre8';
43 $phpMailer->CharSet = PHPMailer::CHARSET_UTF8;
44 $phpMailer->Encoding = PHPMailer::ENCODING_QUOTED_PRINTABLE;
45 $phpMailer->XMailer = ' ';
46 // avoid triggering automated (vacation) responses
47 $phpMailer->addCustomHeader('Auto-Submitted', 'yes');
48 $phpMailer->setLanguage(StaticContainer::get('Piwik\Translation\Translator')->getCurrentLanguage());
49 $this->initSmtpTransport($phpMailer);
50
51 if ($mail->isSmtpDebugEnabled()) {
52 $phpMailer->SMTPDebug = SMTP::DEBUG_SERVER;
53 }
54
55 $phpMailer->Subject = $mail->getSubject();
56
57 $htmlContent = $mail->getBodyHtml();
58 $textContent = $mail->getBodyText();
59
60 if (!empty($htmlContent)) {
61 $phpMailer->msgHTML($htmlContent);
62
63 if (!empty($textContent)) {
64 $phpMailer->AltBody = $textContent;
65 }
66 } else {
67 $phpMailer->Body = $textContent;
68 }
69
70 $phpMailer->setFrom($mail->getFrom(), $mail->getFromName());
71
72 foreach ($mail->getRecipients() as $address => $name) {
73 $phpMailer->addAddress($address, $name);
74 }
75
76 foreach ($mail->getBccs() as $address => $name) {
77 $phpMailer->addBCC($address, $name);
78 }
79
80 foreach ($mail->getReplyTos() as $address => $name) {
81 $phpMailer->addReplyTo($address, $name);
82 }
83
84 foreach ($mail->getAttachments() as $attachment) {
85 if (!empty($attachment['cid'])) {
86 $phpMailer->addStringEmbeddedImage(
87 $attachment['content'],
88 $attachment['cid'],
89 $attachment['filename'],
90 PHPMailer::ENCODING_BASE64,
91 $attachment['mimetype']
92 );
93 } else {
94 $phpMailer->addStringAttachment(
95 $attachment['content'],
96 $attachment['filename'],
97 PHPMailer::ENCODING_BASE64,
98 $attachment['mimetype']
99 );
100 }
101 }
102
103 if (defined('PIWIK_TEST_MODE')) { // hack
104 /**
105 * @ignore
106 * @internal
107 */
108 Piwik::postTestEvent("Test.Mail.send", array($phpMailer));
109 return true;
110 }
111
112 return $phpMailer->send();
113 }
114
115 /**
116 * @return void
117 */
118 private function initSmtpTransport(PHPMailer $phpMailer)
119 {
120 $mailConfig = Config::getInstance()->mail;
121
122 if (empty($mailConfig['host'])
123 || $mailConfig['transport'] != 'smtp'
124 ) {
125 return;
126 }
127
128 $phpMailer->isSMTP();
129
130 if (!empty($mailConfig['type'])) {
131 $phpMailer->SMTPAuth = true;
132 $phpMailer->AuthType = strtoupper($mailConfig['type']);
133 }
134
135 if (!empty($mailConfig['username'])) {
136 $phpMailer->Username = $mailConfig['username'];
137 }
138
139 if (!empty($mailConfig['password'])) {
140 $phpMailer->Password = $mailConfig['password'];
141 }
142
143 if (!empty($mailConfig['encryption'])) {
144 if (strtolower($mailConfig['encryption']) === 'none') {
145 $phpMailer->SMTPAutoTLS = false; // force using no encryption
146 } else {
147 $phpMailer->SMTPSecure = $mailConfig['encryption'];
148 }
149 }
150
151 if (!empty($mailConfig['port'])) {
152 $phpMailer->Port = $mailConfig['port'];
153 }
154
155 $phpMailer->Host = trim($mailConfig['host']);
156 }
157 }
158