You are here

function mimemail_send_email_action in Mime Mail 7

Implements a configurable Drupal action. Sends an email.

File

modules/mimemail_action/mimemail_action.module, line 25
Provide actions for Mime Mail.

Code

function mimemail_send_email_action($entity, $context) {
  if (empty($context['node'])) {
    if (get_class($entity) == 'OgMembership') {
      $context['user'] = user_load($entity->etid);
    }
    else {
      $context['node'] = $entity;
    }
  }
  $to = token_replace($context['to'], $context);

  // If the recipient is a registered user with a language preference, use
  // the recipient's preferred language. Otherwise, use the system default
  // language.
  $account = user_load_by_mail($to);
  if ($account) {
    $language = user_preferred_language($account);
  }
  else {
    $language = language_default();
  }
  $params = array(
    'context' => array(
      'subject' => token_replace($context['subject'], $context),
      'body' => token_replace($context['body'], $context),
    ),
    'key' => $context['key'],
    'cc' => $context['cc'],
    'bcc' => $context['bcc'],
    'reply-to' => $context['reply-to'],
    'plaintext' => token_replace($context['plaintext'], $context),
    'attachments' => $context['attachments'],
  );
  drupal_mail('mimemail', $context['key'], $to, $language, $params);
}