Contributions API

Calling all Drupal developers!

Help us get this on the first page of Digg. DIGG NOW!

Modules in 6

token_actions_send_email_action

Definition

token_actions_send_email_action($object, $context)
contributions/token/token_actions.module, line 119

Description

Implementation of a configurable Drupal action. Sends an email.

Code

<?php
function token_actions_send_email_action($object, $context) {
  $context['global'] = NULL;
  if (!empty($context['node']) && empty($context['user'])) {
    $context['user'] = user_load(array('uid' => $context['node']->uid));
  }
  $from = variable_get('site_mail', ini_get('sendmail_from'));
  $recipient = token_replace_all($context['recipient'], $context);

  $subject = token_replace_all($context['subject'], $context);
  $subject = str_replace(array("\r", "\n"), '', $subject);
  $message = token_replace_all($context['message'], $context);
  $body = drupal_html_to_text($message);

  if (drupal_mail('action_send_email', $recipient, $subject, $body, $from )) {
    watchdog('action', 'Sent email to %recipient', array('%recipient' => $recipient));
  }
  else {
    watchdog('error', 'Unable to send email to %recipient', array('%recipient' => $recipient));
  }
}
?>