]>
git.wh0rd.org - tt-rss.git/blob - classes/mailer.php
3 // TODO: support HTML mail (i.e. MIME messages)
5 private $last_error = "Unable to send mail: check local configuration.";
7 function mail($params) {
9 $to_name = $params["to_name"];
10 $to_address = $params["to_address"];
11 $subject = $params["subject"];
12 $message = $params["message"];
13 $message_html = $params["message_html"];
14 $from_name = $params["from_name"] ?
$params["from_name"] : SMTP_FROM_NAME
;
15 $from_address = $params["from_address"] ?
$params["from_address"] : SMTP_FROM_ADDRESS
;
17 $additional_headers = $params["headers"] ?
$params["headers"] : [];
19 $from_combined = $from_name ?
"$to_name <$to_address>" : $to_address;
20 $to_combined = $to_name ?
"$to_name <$to_address>" : $to_address;
22 Logger
::get()->log("Sending mail from $from_combined to $to_combined <$to_address> [$subject]: $message");
24 // HOOK_SEND_MAIL plugin instructions:
25 // 1. return 1 or true if mail is handled
26 // 2. return -1 if there's been a fatal error and no further action is allowed
27 // 3. any other return value will allow cycling to the next handler and, eventually, to default mail() function
28 // 4. set error message if needed via passed Mailer instance function set_error()
30 foreach (PluginHost
::getInstance()->get_hooks(PluginHost
::HOOK_SEND_MAIL
) as $p) {
31 $rc = $p->hook_send_mail($this, $params);
40 $headers[] = "From: $from_combined";
42 return mail($to_combined, $subject, $message, implode("\r\n", array_merge($headers, $additional_headers)));
45 function set_error($message) {
46 $this->last_error
= $message;
50 return $this->last_error
;