]> git.wh0rd.org - tt-rss.git/blame - classes/mailer.php
pngcrush.sh
[tt-rss.git] / classes / mailer.php
CommitLineData
57932e18
AD
1<?php
2class Mailer {
e08990f7 3 // TODO: support HTML mail (i.e. MIME messages)
57932e18 4
e08990f7 5 private $last_error = "Unable to send mail: check local configuration.";
57932e18 6
e08990f7 7 function mail($params) {
57932e18 8
e08990f7
AD
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;
55bf4bc1 16
e08990f7 17 $additional_headers = $params["headers"] ? $params["headers"] : [];
57932e18 18
e08990f7
AD
19 $from_combined = $from_name ? "$to_name <$to_address>" : $to_address;
20 $to_combined = $to_name ? "$to_name <$to_address>" : $to_address;
57932e18 21
e08990f7 22 Logger::get()->log("Sending mail from $from_combined to $to_combined <$to_address> [$subject]: $message");
57932e18 23
e08990f7
AD
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()
57932e18 29
e08990f7
AD
30 foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_SEND_MAIL) as $p) {
31 $rc = $p->hook_send_mail($this, $params);
57932e18 32
e08990f7
AD
33 if ($rc == 1)
34 return $rc;
ac5e55c2 35
e08990f7
AD
36 if ($rc == -1)
37 return 0;
38 }
57932e18 39
e08990f7 40 $headers[] = "From: $from_combined";
55bf4bc1 41
e08990f7
AD
42 return mail($to_combined, $subject, $message, implode("\r\n", array_merge($headers, $additional_headers)));
43 }
57932e18 44
e08990f7
AD
45 function set_error($message) {
46 $this->last_error = $message;
47 }
57932e18 48
e08990f7
AD
49 function error() {
50 return $this->last_error;
51 }
57932e18 52}