]> git.wh0rd.org - tt-rss.git/blob - classes/mailer.php
remove PHPMailer and related directives from config.php-dist; add pluggable Mailer...
[tt-rss.git] / classes / mailer.php
1 <?php
2 class Mailer {
3 // TODO: support HTML mail (i.e. MIME messages)
4
5 private $last_error = "Unable to send mail: check local configuration.";
6
7 function mail($params) {
8
9 $to = $params["to"];
10 $subject = $params["subject"];
11 $message = $params["message"];
12 $message_html = $params["message_html"];
13 $from = $params["from"] ? $params["from"] : SMTP_FROM_NAME . " <" . SMTP_FROM_ADDRESS . ">";
14 $additional_headers = $params["headers"] ? $params["headers"] : [];
15
16 $headers[] = "From: $from";
17
18 Logger::get()->log("Sending mail from $from to $to [$subject]: $message");
19
20 // HOOK_SEND_MAIL plugin instructions:
21 // 1. return 1 or true if mail is handled
22 // 2. return -1 if there's been a fatal error and no further action is allowed
23 // 3. any other return value will allow cycling to the next handler and, eventually, to default mail() function
24 // 4. set error message if needed via passed Mailer instance function set_error()
25
26 foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_SEND_MAIL) as $p) {
27 $rc = $p->hook_send_mail($this, $params);
28
29 if ($rc == 1 || $rc == -1)
30 return $rc;
31 }
32
33 return mail($to, $subject, $message, implode("\r\n", array_merge($headers, $additional_headers)));
34 }
35
36 function set_error($message) {
37 $this->last_error = $message;
38 }
39
40 function error($value) {
41 return $this->last_error;
42 }
43 }