aboutsummaryrefslogtreecommitdiff
path: root/engine/lib/notification.php
diff options
context:
space:
mode:
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-05-14 16:27:08 +0000
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-05-14 16:27:08 +0000
commit6ba1737c22a002a71210fcd15ad36c3c2bc68402 (patch)
tree22e44b38f986ac94ecb7d831d043d87ac687bf27 /engine/lib/notification.php
parent368c947601348a68dd6805658e637a1e634779e5 (diff)
downloadelgg-6ba1737c22a002a71210fcd15ad36c3c2bc68402.tar.gz
elgg-6ba1737c22a002a71210fcd15ad36c3c2bc68402.tar.bz2
merge -r5832:5898 from 1.7 to trunk.
git-svn-id: http://code.elgg.org/elgg/trunk@6055 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/lib/notification.php')
-rw-r--r--engine/lib/notification.php72
1 files changed, 72 insertions, 0 deletions
diff --git a/engine/lib/notification.php b/engine/lib/notification.php
index 024881e0f..58e2a10f6 100644
--- a/engine/lib/notification.php
+++ b/engine/lib/notification.php
@@ -309,6 +309,78 @@ function email_notify_handler(ElggEntity $from, ElggUser $to, $subject, $message
}
/**
+ * Send an email to any email address
+ *
+ * @param string $from Email address or string: "name <email>"
+ * @param string $to Email address or string: "name <email>"
+ * @param string $subject The subject of the message
+ * @param string $body The message body
+ * @param array $params Optional parameters (none used in this function)
+ * @return bool
+ */
+function elgg_send_email($from, $to, $subject, $body, array $params = NULL) {
+ global $CONFIG;
+
+ if (!$from) {
+ throw new NotificationException(sprintf(elgg_echo('NotificationException:NoEmailAddress'), 'from'));
+ }
+
+ if (!$to) {
+ throw new NotificationException(sprintf(elgg_echo('NotificationException:NoEmailAddress'), 'to'));
+ }
+
+ // return TRUE/FALSE to stop elgg_send_email() from sending
+ $mail_params = array( 'to' => $to,
+ 'from' => $from,
+ 'subject' => $subject,
+ 'body' => $body,
+ 'params' => $params);
+ $result = trigger_plugin_hook('email', 'system', $mail_params, NULL);
+ if ($result !== NULL) {
+ return $result;
+ }
+
+ $header_eol = "\r\n";
+ if (isset($CONFIG->broken_mta) && $CONFIG->broken_mta) {
+ // Allow non-RFC 2822 mail headers to support some broken MTAs
+ $header_eol = "\n";
+ }
+
+ // Windows is somewhat broken, so we use just address for to and from
+ if (strtolower(substr(PHP_OS, 0 , 3)) == 'win') {
+ // strip name from to and from
+ if (strpos($to, '<')) {
+ preg_match('/<(.*)>/', $to, $matches);
+ $to = $matches[1];
+ }
+ if (strpos($from, '<')) {
+ preg_match('/<(.*)>/', $from, $matches);
+ $from = $matches[1];
+ }
+ }
+
+ $headers = "From: $from{$header_eol}"
+ . "Content-Type: text/plain; charset=UTF-8; format=flowed{$header_eol}"
+ . "MIME-Version: 1.0{$header_eol}"
+ . "Content-Transfer-Encoding: 8bit{$header_eol}";
+
+
+ // Sanitise subject by stripping line endings
+ $subject = preg_replace("/(\r\n|\r|\n)/", " ", $subject);
+ if (is_callable('mb_encode_mimeheader')) {
+ $subject = mb_encode_mimeheader($subject,"UTF-8", "B");
+ }
+
+ // Format message
+ $message = html_entity_decode($body, ENT_COMPAT, 'UTF-8'); // Decode any html entities
+ $message = strip_tags($body); // Strip tags from message
+ $message = preg_replace("/(\r\n|\r)/", "\n", $body); // Convert to unix line endings in body
+ $message = preg_replace("/^From/", ">From", $body); // Change lines starting with From to >From
+
+ return mail($to, $subject, wordwrap($body), $headers);
+}
+
+/**
* Correctly initialise notifications and register the email handler.
*
*/