Go to the source code of this file.
Functions | |
drupal_mail ($module, $key, $to, $language, $params=array(), $from=NULL, $send=TRUE) | |
drupal_mail_send ($message) | |
drupal_wrap_mail ($text, $indent= '') | |
drupal_html_to_text ($string, $allowed_tags=NULL) | |
_drupal_wrap_mail_line (&$line, $key, $values) | |
_drupal_html_to_mail_urls ($match=NULL, $reset=FALSE) | |
_drupal_html_to_text_clean ($indent) | |
_drupal_html_to_text_pad ($text, $pad, $prefix= '') |
_drupal_html_to_mail_urls | ( | $ | match = NULL , |
|
$ | reset = FALSE | |||
) |
Helper function for drupal_html_to_text().
Keeps track of URLs and replaces them with placeholder tokens.
Definition at line 435 of file mail.inc.
References $base_url, and $url.
Referenced by drupal_html_to_text().
_drupal_html_to_text_clean | ( | $ | indent | ) |
Helper function for drupal_wrap_mail() and drupal_html_to_text().
Replace all non-quotation markers from a given piece of indentation with spaces.
Definition at line 462 of file mail.inc.
Referenced by drupal_wrap_mail().
_drupal_html_to_text_pad | ( | $ | text, | |
$ | pad, | |||
$ | prefix = '' | |||
) |
Helper function for drupal_html_to_text().
Pad the last line with the given character.
Definition at line 471 of file mail.inc.
Referenced by drupal_html_to_text().
_drupal_wrap_mail_line | ( | &$ | line, | |
$ | key, | |||
$ | values | |||
) |
Helper function for array_walk in drupal_wrap_mail().
Wraps words on a single line.
Definition at line 423 of file mail.inc.
Referenced by drupal_wrap_mail().
drupal_html_to_text | ( | $ | string, | |
$ | allowed_tags = NULL | |||
) |
Transform an HTML string into plain text, preserving the structure of the markup. Useful for preparing the body of a node to be sent by e-mail.
The output will be suitable for use as 'format=flowed; delsp=yes' text (RFC 3676) and can be passed directly to drupal_mail() for sending.
We deliberately use LF rather than CRLF, see drupal_mail().
This function provides suitable alternatives for the following tags:
<blockquote>
Definition at line 261 of file mail.inc.
References $output, $value, _drupal_html_to_mail_urls(), _drupal_html_to_text_pad(), decode_entities(), and drupal_wrap_mail().
drupal_mail | ( | $ | module, | |
$ | key, | |||
$ | to, | |||
$ | language, | |||
$ | params = array() , |
|||
$ | from = NULL , |
|||
$ | send = TRUE | |||
) |
Compose and optionally send an e-mail message.
Sending an e-mail works with defining an e-mail template (subject, text and possibly e-mail headers) and the replacement values to use in the appropriate places in the template. Processed e-mail templates are requested from hook_mail() from the module sending the e-mail. Any module can modify the composed e-mail message array using hook_mail_alter(). Finally drupal_mail_send() sends the e-mail, which can be reused if the exact same composed e-mail is to be sent to multiple recipients.
Finding out what language to send the e-mail with needs some consideration. If you send e-mail to a user, her preferred language should be fine, so use user_preferred_language(). If you send email based on form values filled on the page, there are two additional choices if you are not sending the e-mail to a user on the site. You can either use the language used to generate the page ($language global variable) or the site default language. See language_default(). The former is good if sending e-mail to the person filling the form, the later is good if you send e-mail to an address previously set up (like contact addresses in a contact form).
Taking care of always using the proper language is even more important when sending e-mails in a row to multiple users. Hook_mail() abstracts whether the mail text comes from an administrator setting or is static in the source code. It should also deal with common mail tokens, only receiving $params which are unique to the actual e-mail at hand.
An example:
function example_notify($accounts) { foreach ($accounts as $account) { $params['account'] = $account; // example_mail() will be called based on the first drupal_mail() parameter. drupal_mail('example', 'notify', $account->mail, user_preferred_language($account), $params); } } function example_mail($key, &$message, $params) { $language = $message['language']; $variables = user_mail_tokens($params['account'], $language); switch($key) { case 'notice': $message['subject'] = t('Notification from !site', $variables, $language->language); $message['body'] = t("Dear !username\n\nThere is new content available on the site.", $variables, $language->language); break; } }
$module | A module name to invoke hook_mail() on. The {$module}_mail() hook will be called to complete the $message structure which will already contain common defaults. | |
$key | A key to identify the e-mail sent. The final e-mail id for e-mail altering will be {$module}_{$key}. | |
$to | The e-mail address or addresses where the message will be sent to. The formatting of this string must comply with RFC 2822. Some examples are: , User <> User <>, Another User <> | |
$language | Language object to use to compose the e-mail. | |
$params | Optional parameters to build the e-mail. | |
$from | Sets From, Reply-To, Return-Path and Error-To to this value, if given. | |
$send | Send the message directly, without calling drupal_mail_send() manually. |
Definition at line 83 of file mail.inc.
References drupal_alter(), drupal_function_exists(), drupal_mail_send(), drupal_set_message(), drupal_wrap_mail(), t(), variable_get(), and watchdog().
Referenced by _update_cron_notify(), contact_mail_page_submit(), and contact_mail_user_submit().
drupal_mail_send | ( | $ | message | ) |
Send an e-mail message, using Drupal variables and default settings. More information in the . See drupal_mail() for information on how $message is composed.
$message | Message array with at least the following elements:
|
Definition at line 173 of file mail.inc.
References $name, $value, mime_header_encode(), and variable_get().
Referenced by drupal_mail().
drupal_wrap_mail | ( | $ | text, | |
$ | indent = '' | |||
) |
Perform format=flowed soft wrapping for mail (RFC 3676).
We use delsp=yes wrapping, but only break non-spaced languages when absolutely necessary to avoid compatibility issues.
We deliberately use LF rather than CRLF, see drupal_mail().
$text | The plain text to process. | |
$indent | (optional) A string to indent the text with. Only '>' characters are repeated on subsequent wrapped lines. Others are replaced by spaces. |
Definition at line 211 of file mail.inc.
References _drupal_html_to_text_clean(), and _drupal_wrap_mail_line().
Referenced by drupal_html_to_text(), and drupal_mail().