From c626b0f08fba3ad8c70ad32c7d97d9938797a420 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 12 May 2023 14:23:59 +0200 Subject: [inc/Mailer] Allow Somename format as FROM --- inc/mailer.inc.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/inc/mailer.inc.php b/inc/mailer.inc.php index 942bfc75..05b6a08c 100644 --- a/inc/mailer.inc.php +++ b/inc/mailer.inc.php @@ -15,9 +15,16 @@ class Mailer /** @var string */ private $errlog = ''; + /** @var string */ + private $from; + // $keys = array('host', 'port', 'ssl', 'senderAddress', 'replyTo', 'username', 'password', 'serverName'); public function __construct(string $hosturi, bool $startTls, string $from, string $user, string $pass, string $replyTo = null) { + $this->from = $from; + if (preg_match('/[^<>"\'\s]+@[^<>"\'\s]+/i', $from, $out)) { + $from = $out[0]; + } $this->curlOptions = [ CURLOPT_URL => $hosturi, CURLOPT_USE_SSL => $startTls ? CURLUSESSL_ALL : CURLUSESSL_TRY, @@ -53,7 +60,7 @@ class Mailer } $mail[] = self::mimeEncode('Content-Type', 'text/plain; charset="utf-8"'); $mail[] = self::mimeEncode('Subject', $subject); - $mail[] = self::mimeEncode('From', $this->curlOptions[CURLOPT_MAIL_FROM]); + $mail[] = self::mimeEncode('From', $this->from); $mail[] = self::mimeEncode('Message-ID', '<' . Util::randomUuid() . '@rfcpedant.example.org>'); if (!empty($this->replyTo)) { $mail[] = self::mimeEncode('Reply-To', $this->replyTo); -- cgit v1.2.3-55-g7522