diff options
author | Dries Buytaert <dries@buytaert.net> | 2006-07-10 08:12:31 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2006-07-10 08:12:31 +0000 |
commit | af976d339f743ceef50200e592b35c849bca3879 (patch) | |
tree | 53bde10dfa62bb4717c2fea1e46d1fa55c4fa47e /includes | |
parent | d3e8a43d4fa34c54040ed8cafc26b43f2e53db78 (diff) | |
download | brdo-af976d339f743ceef50200e592b35c849bca3879.tar.gz brdo-af976d339f743ceef50200e592b35c849bca3879.tar.bz2 |
- Patch #71194 by Goba: introducing hook_mail_alter(), chaning user_mail() to drupal_mail().
Diffstat (limited to 'includes')
-rw-r--r-- | includes/common.inc | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/includes/common.inc b/includes/common.inc index 828d6e116..5ee01d2ee 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -1405,3 +1405,85 @@ function page_set_cache() { } } } + +/** + * Send an e-mail message, using Drupal variables and default settings. + * More information in the <a href="http://php.net/manual/en/function.mail.php"> + * PHP function reference for mail()</a> + * @param $mailkey + * A key to indetify the mail sent, for altering + * @param $to + * The mail address or addresses where the message will be send to. The + * formatting of this string must comply with RFC 2822. Some examples are: + * user@example.com + * user@example.com, anotheruser@example.com + * User <user@example.com> + * User <user@example.com>, Another User <anotheruser@example.com> + * @param $subject + * Subject of the e-mail to be sent. This must not contain any newline + * characters, or the mail may not be sent properly. + * @param $body + * Message to be sent. Drupal will format the correct line endings for you. + * @param $from + * Sets From, Reply-To, Return-Path and Error-To to this value, if given. + * @param $headers + * Associative array containing the headers to add. This is typically + * used to add extra headers (From, Cc, and Bcc). + * <em>When sending mail, the mail must contain a From header.</em> + * @return Returns TRUE if the mail was successfully accepted for delivery, + * FALSE otherwise. + */ +function drupal_mail($mailkey, $to, $subject, $body, $from = NULL, $headers = array()) { + $defaults = array( + 'MIME-Version' => '1.0', + 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed', + 'Content-Transfer-Encoding' => '8Bit', + 'X-Mailer' => 'Drupal' + ); + if (isset($from)) { + $defaults['From'] = $defaults['Reply-To'] = $defaults['Return-Path'] = $defaults['Errors-To'] = $from; + } + $headers = array_merge($defaults, $headers); + // Custom hook traversal to allow pass by reference + foreach (module_implements('mail_alter') AS $module) { + $function = $module .'_mail_alter'; + $function($mailkey, $to, $subject, $body, $from, $headers); + } + // Allow for custom mail backend + if (variable_get('smtp_library', '') && file_exists(variable_get('smtp_library', ''))) { + include_once './' . variable_get('smtp_library', ''); + return drupal_mail_wrapper($mailkey, $to, $subject, $body, $from, $headers); + } + else { + /* + ** Note: if you are having problems with sending mail, or mails look wrong + ** when they are received you may have to modify the str_replace to suit + ** your systems. + ** - \r\n will work under dos and windows. + ** - \n will work for linux, unix and BSDs. + ** - \r will work for macs. + ** + ** According to RFC 2646, it's quite rude to not wrap your e-mails: + ** + ** "The Text/Plain media type is the lowest common denominator of + ** Internet e-mail, with lines of no more than 997 characters (by + ** convention usually no more than 80), and where the CRLF sequence + ** represents a line break [MIME-IMT]." + ** + ** CRLF === \r\n + ** + ** http://www.rfc-editor.org/rfc/rfc2646.txt + ** + */ + $mimeheaders = array(); + foreach ($headers as $name => $value) { + $mimeheaders[] = $name .': '. mime_header_encode($value); + } + return mail( + $to, + mime_header_encode($subject), + str_replace("\r", '', $body), + join("\n", $mimeheaders) + ); + } +} |