From: Andrew Dolgov Date: Thu, 22 Nov 2018 13:36:10 +0000 (+0300) Subject: mailer: split to/from name/addresses X-Git-Tag: 18.12~44 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=55bf4bc1d3e10b35f54c42b10207484fcb3d10fd;p=tt-rss.git mailer: split to/from name/addresses --- diff --git a/classes/digest.php b/classes/digest.php index 641fbe97..ba1f2242 100644 --- a/classes/digest.php +++ b/classes/digest.php @@ -58,7 +58,8 @@ class Digest //$rc = $mail->quickMail($line["email"], $line["login"], DIGEST_SUBJECT, $digest, $digest_text); - $rc = $mailer->mail(["to" => $line["login"] . " <" . $line["email"] . ">", + $rc = $mailer->mail(["to_name" => $line["login"], + "to_address" => $line["email"], "subject" => DIGEST_SUBJECT, "message" => $digest_text, "message_html" => $digest]); diff --git a/classes/mailer.php b/classes/mailer.php index ae22776d..f67690e8 100644 --- a/classes/mailer.php +++ b/classes/mailer.php @@ -6,16 +6,20 @@ class Mailer { function mail($params) { - $to = $params["to"]; + $to_name = $params["to_name"]; + $to_address = $params["to_address"]; $subject = $params["subject"]; $message = $params["message"]; $message_html = $params["message_html"]; - $from = $params["from"] ? $params["from"] : SMTP_FROM_NAME . " <" . SMTP_FROM_ADDRESS . ">"; + $from_name = $params["from_name"] ? $params["from_name"] : SMTP_FROM_NAME; + $from_address = $params["from_address"] ? $params["from_address"] : SMTP_FROM_ADDRESS; + $additional_headers = $params["headers"] ? $params["headers"] : []; - $headers[] = "From: $from"; + $from_combined = $from_name ? "$to_name <$to_address>" : $to_address; + $to_combined = $to_name ? "$to_name <$to_address>" : $to_address; - Logger::get()->log("Sending mail from $from to $to [$subject]: $message"); + Logger::get()->log("Sending mail from $from_combined to $to_combined <$to_address> [$subject]: $message"); // HOOK_SEND_MAIL plugin instructions: // 1. return 1 or true if mail is handled @@ -30,14 +34,16 @@ class Mailer { return $rc; } - return mail($to, $subject, $message, implode("\r\n", array_merge($headers, $additional_headers))); + $headers[] = "From: $from_combined"; + + return mail($to_combined, $subject, $message, implode("\r\n", array_merge($headers, $additional_headers))); } function set_error($message) { $this->last_error = $message; } - function error($value) { + function error() { return $this->last_error; } } diff --git a/classes/pref/users.php b/classes/pref/users.php index ad48e7a7..f1526a8f 100644 --- a/classes/pref/users.php +++ b/classes/pref/users.php @@ -305,7 +305,8 @@ class Pref_Users extends Handler_Protected { $mailer = new Mailer(); - $rc = $mailer->mail(["to" => "$login <$email>", + $rc = $mailer->mail(["to_name" => $login, + "to_address" => $email, "subject" => __("[tt-rss] Password change notification"), "message" => $message]); diff --git a/plugins/mail/init.php b/plugins/mail/init.php index 1b31a220..5294931c 100644 --- a/plugins/mail/init.php +++ b/plugins/mail/init.php @@ -205,7 +205,7 @@ class Mail extends Plugin { $mailer = new Mailer(); - $mailer->mail(["to" => $to, + $rc = $mailer->mail(["to_address" => $to, "headers" => ["Reply-To: $from"], "subject" => $subject, "message" => $message]); diff --git a/register.php b/register.php index 98d49319..8bbce993 100644 --- a/register.php +++ b/register.php @@ -308,7 +308,7 @@ "If that wasn't you, just ignore this message. Thanks."; $mailer = new Mailer(); - $rc = $mailer->mail(["to" => $email, + $rc = $mailer->mail(["to_address" => $email, "subject" => "Registration information for Tiny Tiny RSS", "message" => $reg_text]); @@ -322,7 +322,7 @@ "Email: $email\n"; $mailer = new Mailer(); - $rc = $mailer->mail(["to" => REG_NOTIFY_ADDRESS, + $rc = $mailer->mail(["to_address" => REG_NOTIFY_ADDRESS, "subject" => "Registration notice for Tiny Tiny RSS", "message" => $reg_text]);