Sends an e-mail message.
object $entity: An optional node entity, which will be added as $context['node'] if provided.
array $context: Array with the following elements:
function action_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) {
$langcode = user_preferred_langcode($recipient_account);
}
else {
$langcode = language_default()->langcode;
}
$params = array(
'context' => $context,
);
if (drupal_mail('system', 'action_send_email', $recipient, $langcode, $params)) {
watchdog('action', 'Sent email to %recipient', array(
'%recipient' => $recipient,
));
}
else {
watchdog('error', 'Unable to send email to %recipient', array(
'%recipient' => $recipient,
));
}
}