You are here

function mimemail_mail in Mime Mail 6

Same name and namespace in other branches
  1. 7 mimemail.module \mimemail_mail()

Implements hook_mail().

Set's the message subject and body as configured in the $settings of the action.

2 string references to 'mimemail_mail'
mimemail_admin_settings in includes/mimemail.admin.inc
Module configuration form.
mimemail_prepare_message in ./mimemail.module
Default engine's prepare function.

File

./mimemail.module, line 84
Component module for sending MIME-encoded e-mails.

Code

function mimemail_mail($key, &$message, $params) {
  $account = $params['account'];
  $variables = array(
    '%site_name' => variable_get('site_name', 'Drupal'),
    '%username' => $account->name,
  );

  // Replace variables.
  if (isset($params['node']) && is_object($params['node'])) {
    $node = $params['node'];
    $variables += array(
      '%author' => $account->mail,
      '%uid' => $node->uid,
      '%node_url' => url('node/' . $node->nid, array(
        'absolute' => TRUE,
      )),
      '%node_type' => $node->type,
      '%title' => $node->title,
      '%teaser' => $node->teaser,
      '%body' => $node->body,
    );
  }

  // Prepare the array of the attachments.
  $attachments = array();
  $attachments_string = trim($params['attachments']);
  if (!empty($attachments_string)) {
    $attachment_lines = array_filter(explode("\n", trim($attachments_string)));
    foreach ($attachment_lines as $key => $attachment_line) {
      $attachment = explode(':', trim($attachment_line), 2);
      $attachments[] = array(
        'filepath' => $attachment[1],
        'filemime' => $attachment[0],
      );
    }
  }

  // We handle different address headers if set.
  $address_headers = array(
    'cc' => 'Cc',
    'bcc' => 'Bcc',
    'reply_to' => 'Reply-to',
  );
  foreach ($address_headers as $param_key => $address_header) {
    $params[$param_key] = empty($params[$param_key]) ? array() : explode(',', $params[$param_key]);
    if (!empty($params[$param_key])) {
      foreach ($params[$param_key] as $key => $address) {
        $params[$param_key][$key] = strtr(str_replace(array(
          "\r",
          "\n",
        ), '', trim($address)), $variables);
      }
      $message['headers'][$address_header] = implode(',', $params[$param_key]);
    }
  }
  $message['to'] = strtr($message['to'], $variables);
  $message['subject'] = strtr($params['subject'], $variables);
  $message['body'][] = check_markup(strtr($params['message_html'], $variables), $params['message_html_filter'], FALSE);
  $message['params']['plaintext'] = strtr($params['message_plaintext'], $variables);
  $message['params']['attachments'] = $attachments;
}