PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 4.3.0
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v4.3.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 5 years ago
Transport.php
150 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 use Piwik\Version;
19
20 class Transport
21 {
22 /**
23 * Sends the given mail
24 *
25 * @param Mail $mail
26 * @return bool
27 * @throws \DI\NotFoundException
28 * @throws \PHPMailer\PHPMailer\Exception
29 */
30 public function send(Mail $mail)
31 {
32 $phpMailer = new PHPMailer(true);
33
34 PHPMailer::$validator = 'pcre8';
35 $phpMailer->CharSet = PHPMailer::CHARSET_UTF8;
36 $phpMailer->Encoding = PHPMailer::ENCODING_QUOTED_PRINTABLE;
37 $phpMailer->XMailer = ' ';
38 // avoid triggering automated (vacation) responses
39 $phpMailer->addCustomHeader('Auto-Submitted', 'yes');
40 $phpMailer->setLanguage(StaticContainer::get('Piwik\Translation\Translator')->getCurrentLanguage());
41 $this->initSmtpTransport($phpMailer);
42
43 if ($mail->isSmtpDebugEnabled()) {
44 $phpMailer->SMTPDebug = SMTP::DEBUG_SERVER;
45 }
46
47 $phpMailer->Subject = $mail->getSubject();
48
49 $htmlContent = $mail->getBodyHtml();
50 $textContent = $mail->getBodyText();
51
52 if (!empty($htmlContent)) {
53 $phpMailer->msgHTML($htmlContent);
54
55 if (!empty($textContent)) {
56 $phpMailer->AltBody = $textContent;
57 }
58 } else {
59 $phpMailer->Body = $textContent;
60 }
61
62 $phpMailer->setFrom($mail->getFrom(), $mail->getFromName());
63
64 foreach ($mail->getRecipients() as $address => $name) {
65 $phpMailer->addAddress($address, $name);
66 }
67
68 foreach ($mail->getBccs() as $address => $name) {
69 $phpMailer->addBCC($address, $name);
70 }
71
72 foreach ($mail->getReplyTos() as $address => $name) {
73 $phpMailer->addReplyTo($address, $name);
74 }
75
76 foreach ($mail->getAttachments() as $attachment) {
77 if (!empty($attachment['cid'])) {
78 $phpMailer->addStringEmbeddedImage(
79 $attachment['content'],
80 $attachment['cid'],
81 $attachment['filename'],
82 PHPMailer::ENCODING_BASE64,
83 $attachment['mimetype']
84 );
85 } else {
86 $phpMailer->addStringAttachment(
87 $attachment['content'],
88 $attachment['filename'],
89 PHPMailer::ENCODING_BASE64,
90 $attachment['mimetype']
91 );
92 }
93 }
94
95 if (defined('PIWIK_TEST_MODE')) { // hack
96 /**
97 * @ignore
98 * @internal
99 */
100 Piwik::postTestEvent("Test.Mail.send", array($phpMailer));
101 return true;
102 }
103
104 return $phpMailer->send();
105 }
106
107 /**
108 * @return void
109 */
110 private function initSmtpTransport(PHPMailer $phpMailer)
111 {
112 $mailConfig = Config::getInstance()->mail;
113
114 if (empty($mailConfig['host'])
115 || $mailConfig['transport'] != 'smtp'
116 ) {
117 return;
118 }
119
120 $phpMailer->isSMTP();
121
122 if (!empty($mailConfig['type'])) {
123 $phpMailer->SMTPAuth = true;
124 $phpMailer->AuthType = strtoupper($mailConfig['type']);
125 }
126
127 if (!empty($mailConfig['username'])) {
128 $phpMailer->Username = $mailConfig['username'];
129 }
130
131 if (!empty($mailConfig['password'])) {
132 $phpMailer->Password = $mailConfig['password'];
133 }
134
135 if (!empty($mailConfig['encryption'])) {
136 if (strtolower($mailConfig['encryption']) === 'none') {
137 $phpMailer->SMTPAutoTLS = false; // force using no encryption
138 } else {
139 $phpMailer->SMTPSecure = $mailConfig['encryption'];
140 }
141 }
142
143 if (!empty($mailConfig['port'])) {
144 $phpMailer->Port = $mailConfig['port'];
145 }
146
147 $phpMailer->Host = trim($mailConfig['host']);
148 }
149 }
150