drupal_mail_send

Versions
6
drupal_mail_send($message)

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>. See drupal_mail() for information on how $message is composed.

Parameters

$message Message array with at least the following elements:

  • id A unique identifier of the e-mail type. Examples: 'contact_user_copy', 'user_password_reset'.
  • to The 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@example.com user@example.com, anotheruser@example.com User <user@example.com> User <user@example.com>, Another User <anotheruser@example.com>
  • subject Subject of the e-mail to be sent. This must not contain any newline characters, or the mail may not be sent properly.
  • body Message to be sent. Accepts both CRLF and LF line-endings. E-mail bodies must be wrapped. You can use drupal_wrap_mail() for smart plain text wrapping.
  • headers Associative array containing all mail headers.

Return value

Returns TRUE if the mail was successfully accepted for delivery, FALSE otherwise.

Code

includes/mail.inc, line 172

<?php
function drupal_mail_send($message) {
  // Allow for a custom mail backend.
  if (variable_get('smtp_library', '') && file_exists(variable_get('smtp_library', ''))) {
    include_once './'. variable_get('smtp_library', '');
    return drupal_mail_wrapper($message);
  }
  else {
    $mimeheaders = array();
    foreach ($message['headers'] as $name => $value) {
      $mimeheaders[] = $name .': '. mime_header_encode($value);
    }
    return mail(
      $message['to'],
      mime_header_encode($message['subject']),
      // Note: e-mail uses CRLF for line-endings, but PHP's API requires LF.
      // They will appear correctly in the actual e-mail that is sent.
      str_replace("\r", '', $message['body']),
      // For headers, PHP's API suggests that we use CRLF normally,
      // but some MTAs incorrecly replace LF with CRLF. See #234403.
      join("\n", $mimeheaders)
    );
  }
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.