function drupal_mail_send

You are here

6 mail.inc 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 5322. Some examples are:

  • 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.

1 call to drupal_mail_send()
drupal_mail in includes/mail.inc
Compose and optionally send an e-mail message.

File

includes/mail.inc, line 173

Code

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));
  }
}

Comments

What happens in Drupal 7? Do we need to use the complex drupal_mail() instead?

Don't follow the link above, it won't help you. You need to use an implementation of that interface. See
http://api.drupal.org/api/drupal/includes--mail.inc/function/drupal_mail...

Just in case anyone cares, hook_mail() allows you to tweak outgoing emails.

drupal_mail_send() DOES NOT travel through this hook however.