You are here

function user_mail in Drupal 4

Same name and namespace in other branches
  1. 8 core/modules/user/user.module \user_mail()
  2. 6 modules/user/user.module \user_mail()
  3. 7 modules/user/user.module \user_mail()
  4. 9 core/modules/user/user.module \user_mail()

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>

Parameters

$mail: The mail adres 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 email to be sent. This must not contain any newline characters, or the mail may not be sent properly. @param $message Message to be sent. Drupal will format the correct line endings for you. @param $header String to be inserted at the end of the email header. This is typically used to add extra headers (From, Cc, and Bcc). Multiple extra headers should be separated with a CRLF (\r\n). <em>When sending mail, the mail must contain a From header.</em>

Return value

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

4 calls to user_mail()
contact_mail_page_submit in modules/contact.module
Process the site-wide contact page form submission.
contact_mail_user_submit in modules/contact.module
Process the personal contact page form submission.
user_pass_submit in modules/user.module
user_register_submit in modules/user.module

File

modules/user.module, line 399
Enables the user registration and login system.

Code

function user_mail($mail, $subject, $message, $header) {
  if (variable_get('smtp_library', '') && file_exists(variable_get('smtp_library', ''))) {
    include_once './' . variable_get('smtp_library', '');
    return user_mail_wrapper($mail, $subject, $message, $header);
  }
  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
     **
     */
    return mail($mail, mime_header_encode($subject), str_replace("\r", '', $message), "MIME-Version: 1.0\nContent-Type: text/plain; charset=UTF-8; format=flowed\nContent-transfer-encoding: 8Bit\n" . $header);
  }
}