You are here

function rules_action_mimemail in Mime Mail 7

Action Implementation: Send HTML mail.

1 string reference to 'rules_action_mimemail'
mimemail_rules_action_info in ./mimemail.rules.inc
Implements hook_rules_action_info().

File

./mimemail.rules.inc, line 275
Rules actions for sending Mime-encoded emails.

Code

function rules_action_mimemail($key, $to, $cc = NULL, $bcc = NULL, $from_name = NULL, $from_mail = NULL, $reply_to = NULL, $list_unsubscribe = NULL, $subject, $body, $plaintext = NULL, $attachments = array(), $langcode, $settings, RulesState $state, RulesPlugin $element) {
  module_load_include('inc', 'mimemail');

  // Set the sender name and from address.
  if (empty($from_mail)) {
    $from = NULL;
  }
  else {
    $from = array(
      'name' => $from_name,
      'mail' => $from_mail,
    );

    // Create an address string.
    $from = mimemail_address($from);
  }

  // Figure out the language to use - fallback is the system default.
  $languages = language_list();
  $language = isset($languages[$langcode]) ? $languages[$langcode] : language_default();
  $params = array(
    'context' => array(
      'subject' => $subject,
      'body' => $body,
      'action' => $element,
      'state' => $state,
    ),
    'cc' => $cc,
    'bcc' => $bcc,
    'reply-to' => $reply_to,
    'list-unsubscribe' => $list_unsubscribe,
    'plaintext' => $plaintext,
    'attachments' => $attachments,
  );
  $message = drupal_mail('mimemail', $key, $to, $language, $params, $from);
  return array(
    'send_status' => !empty($message['result']),
  );
}