]> git.wh0rd.org Git - tt-rss.git/commitdiff
mailer: split to/from name/addresses
authorAndrew Dolgov <noreply@fakecake.org>
Thu, 22 Nov 2018 13:36:10 +0000 (16:36 +0300)
committerAndrew Dolgov <noreply@fakecake.org>
Thu, 22 Nov 2018 13:36:10 +0000 (16:36 +0300)
classes/digest.php
classes/mailer.php
classes/pref/users.php
plugins/mail/init.php
register.php

index 641fbe97f4b9b2a12c7257ebf301711363399a24..ba1f224250f04abf2d15a350ef5eb302f66ff77a 100644 (file)
@@ -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]);
index ae22776d4d71c1c567ba5929ce713112bb2ac624..f67690e806476c2d7470f0611c0c60ebb5a8fffd 100644 (file)
@@ -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;
   }
 }
index ad48e7a722a4b5be521a544da2b3fdf353859c25..f1526a8f3b1a2ac92c02f411a399ff64f14558dc 100644 (file)
@@ -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]);
 
index 1b31a220b06b82aa828fa23e0300709ceb6e57df..5294931c7c8308add9051df17dc16f57cba9aa78 100644 (file)
@@ -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]);
index 98d49319d112e8b441aef1097f80909b189a05c4..8bbce99328b31186e01c1a416712db8501c3dc89 100644 (file)
                                                "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]);
 
                                                "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]);