mailer: split to/from name/addresses

This commit is contained in:
Andrew Dolgov 2018-11-22 16:36:10 +03:00
parent 57932e1837
commit 55bf4bc1d3
5 changed files with 19 additions and 11 deletions

View 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]);

View 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;
}
}

View 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]);

View 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]);

View File

@ -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]);