You are here

function mimemail_prepare in Mime Mail 5

Sends a mime-encoded e-mail.

This function first determines the mail engine to use, then prepares the message by calling the mail engine's prepare function, or mimemail_prepare() if another one does not exist, then sends the message.

Parameters

$sender: The email address or user object who is sending the message.

$recipient+ : An email address or user object who is receiving the message.

$subject: A subject line string.

$body: The message body in HTML format.

$plaintext: Whether to send the message as plaintext only or HTML. If set to 1, Yes or TRUE, then the message will be sent as plaintext.

$headers: Optional e-mail headers in a keyed array.

$text: Optional plaintext portion of a multipart e-mail.

$attachments: An array of arrays which describe one or more attachments. The internal array consists of two parts: the file's path and the file's MIME type. The array of arrays looks something like this: Array ( [0] => Array ( [filepath] => '/path/to/file.name' [filemime] => 'mime/type' ) )

$mailkey: An identifier for the message.

Return value

An array containing the MIME encoded message, including headers and body.

1 call to mimemail_prepare()
mimemail in ./mimemail.module

File

./mimemail.module, line 201
Component module for sending Mime-encoded emails.

Code

function mimemail_prepare($sender, $recipient, $subject, $body, $plaintext = NULL, $headers = array(), $text = NULL, $attachments = array(), $mailkey = '') {
  require_once dirname(__FILE__) . '/mimemail.inc';
  if (is_null($sender)) {

    // use site default for sender
    $sender = array(
      'name' => variable_get('site_name', 'Drupal'),
      'mail' => variable_get('site_mail', ini_get('sendmail_from')),
    );
  }

  // try to determine recpient's text mail preference
  if (is_null($plaintext)) {
    if (is_object($recipient)) {
      if (isset($recipient->mimemail_textonly)) {
        $plaintext = $recipient->mimemail_textonly;
      }
    }
    elseif (is_string($recipient) && valid_email_address($recipient)) {
      if (is_object($r = user_load(array(
        'mail' => $recipient,
      ))) && isset($r->mimemail_textonly)) {
        $plaintext = $r->mimemail_textonly;
        $recipient = $r;

        // might as well pass the user object to the address function
      }
    }
  }
  $subject = mime_header_encode($subject);
  $plaintext = $plaintext || variable_get('mimemail_textonly', 0);
  $sender = mimemail_address($sender);
  $mail = mimemail_html_body(theme('mimemail_message', $body, $mailkey), $subject, $plaintext, $text, $attachments);
  $headers = array_merge($headers, $mail['headers']);
  $message = array(
    'address' => mimemail_address($recipient),
    'subject' => $subject,
    'body' => $mail['body'],
    'sender' => $sender,
    'headers' => mimemail_headers($headers, $sender),
  );
  return $message;
}