You are here

function mimemail_mail in Mime Mail 7

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

Implements hook_mail().

3 string references to 'mimemail_mail'
mimemail_admin_settings in includes/mimemail.admin.inc
Configuration form.
mimemail_prepare_message in ./mimemail.module
Prepares the message for sending.
mimemail_uninstall in ./mimemail.install
Implements hook_uninstall().

File

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

Code

function mimemail_mail($key, &$message, $params) {
  $context = $params['context'];
  $options = array(
    'clear' => TRUE,
  );

  // 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 $filepath) {
      $attachments[] = array(
        'filepath' => trim($filepath),
      );
    }
  }

  // We handle different address headers if set.
  $address_headers = array(
    'cc' => 'Cc',
    'bcc' => 'Bcc',
    'reply-to' => 'Reply-to',
    'list-unsubscribe' => 'List-Unsubscribe',
  );
  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] = token_replace($address, $context, $options);
      }
      $message['headers'][$address_header] = implode(',', $params[$param_key]);
    }
  }
  $message['to'] = token_replace($message['to'], $context, $options);
  $message['subject'] = token_replace($context['subject'], $context, $options);
  $message['body'][] = token_replace($context['body'], $context, $options);
  $message['params']['plaintext'] = token_replace($params['plaintext'], $context, $options);
  $message['params']['attachments'] = $attachments;
}