Same name and namespace in other branches
  1. 6.x modules/system/system.module \system_send_email_action()

Sends an e-mail message.

Parameters

object $entity: An optional node object, which will be added as $context['node'] if provided.

array $context: Array with the following elements:

  • 'recipient': E-mail message recipient. This will be passed through token_replace().
  • 'subject': The subject of the message. This will be passed through token_replace().
  • 'message': The message to send. This will be passed through token_replace().
  • Other elements will be used as the data for token replacement.

Related topics

2 string references to 'system_send_email_action'
system_action_info in modules/system/system.module
Implements hook_action_info().
TriggerActionTestCase::assignSystemEmailAction in modules/trigger/trigger.test
Assigns a system_send_email_action to the passed-in trigger.

File

modules/system/system.module, line 3275
Configuration system that lets administrators modify the workings of the site.

Code

function system_send_email_action($entity, $context) {
  if (empty($context['node'])) {
    $context['node'] = $entity;
  }
  $recipient = token_replace($context['recipient'], $context);

  // If the recipient is a registered user with a language preference, use
  // the recipient's preferred language. Otherwise, use the system default
  // language.
  $recipient_account = user_load_by_mail($recipient);
  if ($recipient_account) {
    $language = user_preferred_language($recipient_account);
  }
  else {
    $language = language_default();
  }
  $params = array(
    'context' => $context,
  );
  if (drupal_mail('system', 'action_send_email', $recipient, $language, $params)) {
    watchdog('action', 'Sent email to %recipient', array(
      '%recipient' => $recipient,
    ));
  }
  else {
    watchdog('error', 'Unable to send email to %recipient', array(
      '%recipient' => $recipient,
    ));
  }
}