PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 5.0.3
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v5.0.3
5.13.0 5.12.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 2 years ago Transport.php 2 years ago
Transport.php
121 lines
1 <?php
2
3 /**
4 * Matomo - free/libre analytics platform
5 *
6 * @link https://matomo.org
7 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
8 *
9 */
10 namespace Piwik\Mail;
11
12 use PHPMailer\PHPMailer\Exception as PHPMailerException;
13 use PHPMailer\PHPMailer\PHPMailer;
14 use PHPMailer\PHPMailer\SMTP;
15 use Piwik\Config;
16 use Piwik\Container\StaticContainer;
17 use Piwik\Exception\DI\DependencyException;
18 use Piwik\Exception\DI\NotFoundException;
19 use Piwik\Mail;
20 use Piwik\Piwik;
21 class Transport
22 {
23 /**
24 * Sends the given mail
25 *
26 * @param Mail $mail
27 * @return bool
28 * @throws DependencyException
29 * @throws PHPMailerException
30 * @throws NotFoundException
31 */
32 public function send(Mail $mail)
33 {
34 $phpMailer = new PHPMailer(true);
35 //check self-signed config in mail
36 $phpMailer->SMTPOptions = ['ssl' => ['verify_peer' => (int) Config::getInstance()->mail['ssl_verify_peer'], 'verify_peer_name' => (int) Config::getInstance()->mail['ssl_verify_peer_name'], 'allow_self_signed' => Config::getInstance()->mail['ssl_disallow_self_signed'] == "1" ? 0 : 1]];
37 PHPMailer::$validator = 'pcre8';
38 $phpMailer->CharSet = PHPMailer::CHARSET_UTF8;
39 $phpMailer->Encoding = PHPMailer::ENCODING_QUOTED_PRINTABLE;
40 $phpMailer->XMailer = ' ';
41 // avoid triggering automated (vacation) responses
42 $phpMailer->addCustomHeader('Auto-Submitted', 'yes');
43 $phpMailer->setLanguage(StaticContainer::get('Piwik\\Translation\\Translator')->getCurrentLanguage());
44 $this->initSmtpTransport($phpMailer);
45 if ($mail->isSmtpDebugEnabled()) {
46 $phpMailer->SMTPDebug = SMTP::DEBUG_SERVER;
47 }
48 $phpMailer->Subject = $mail->getSubject();
49 $htmlContent = $mail->getBodyHtml();
50 $textContent = $mail->getBodyText();
51 if (!empty($htmlContent)) {
52 $phpMailer->msgHTML($htmlContent);
53 if (!empty($textContent)) {
54 $phpMailer->AltBody = $textContent;
55 }
56 } else {
57 $phpMailer->Body = $textContent;
58 }
59 $phpMailer->setFrom($mail->getFrom(), $mail->getFromName());
60 foreach ($mail->getRecipients() as $address => $name) {
61 $phpMailer->addAddress($address, $name);
62 }
63 foreach ($mail->getBccs() as $address => $name) {
64 $phpMailer->addBCC($address, $name);
65 }
66 foreach ($mail->getReplyTos() as $address => $name) {
67 $phpMailer->addReplyTo($address, $name);
68 }
69 foreach ($mail->getAttachments() as $attachment) {
70 if (!empty($attachment['cid'])) {
71 $phpMailer->addStringEmbeddedImage($attachment['content'], $attachment['cid'], $attachment['filename'], PHPMailer::ENCODING_BASE64, $attachment['mimetype']);
72 } else {
73 $phpMailer->addStringAttachment($attachment['content'], $attachment['filename'], PHPMailer::ENCODING_BASE64, $attachment['mimetype']);
74 }
75 }
76 if (defined('PIWIK_TEST_MODE')) {
77 // hack
78 /**
79 * @ignore
80 * @internal
81 */
82 Piwik::postTestEvent("Test.Mail.send", array($phpMailer));
83 return true;
84 }
85 return $phpMailer->send();
86 }
87 /**
88 * @return void
89 */
90 private function initSmtpTransport(PHPMailer $phpMailer)
91 {
92 $mailConfig = Config::getInstance()->mail;
93 if (empty($mailConfig['host']) || $mailConfig['transport'] != 'smtp') {
94 return;
95 }
96 $phpMailer->isSMTP();
97 if (!empty($mailConfig['type'])) {
98 $phpMailer->SMTPAuth = true;
99 $phpMailer->AuthType = strtoupper($mailConfig['type']);
100 }
101 if (!empty($mailConfig['username'])) {
102 $phpMailer->Username = $mailConfig['username'];
103 }
104 if (!empty($mailConfig['password'])) {
105 $phpMailer->Password = $mailConfig['password'];
106 }
107 if (!empty($mailConfig['encryption'])) {
108 if (strtolower($mailConfig['encryption']) === 'none') {
109 $phpMailer->SMTPAutoTLS = false;
110 // force using no encryption
111 } else {
112 $phpMailer->SMTPSecure = $mailConfig['encryption'];
113 }
114 }
115 if (!empty($mailConfig['port'])) {
116 $phpMailer->Port = $mailConfig['port'];
117 }
118 $phpMailer->Host = trim($mailConfig['host']);
119 }
120 }
121