You are here

function library_send_email_action in Library 6

Same name and namespace in other branches
  1. 5.2 library.actions.inc \library_send_email_action()
  2. 6.2 library.actions.inc \library_send_email_action()
  3. 7 library.actions.inc \library_send_email_action()

Implementation of a configurable Drupal action. Sends an email.

File

./library.actions.inc, line 204
Hooks into core Drupal actions module

Code

function library_send_email_action(&$object, $context) {
  $recipient = $context['recipient'];
  $patron = $context['patron'];
  $language = language_default();
  if (!empty($patron->uid)) {
    $account = user_load($patron->uid);
    $language = user_preferred_language($account);
  }
  if ($recipient == '%patron_email') {
    $recipient = $context['patron']['email'];
  }
  $params = array(
    'context' => $context,
  );
  if (drupal_mail('library', 'action_send_email', $recipient, $language, $params)) {
    watchdog('library', 'Sent email to %recipient', array(
      '%recipient' => $recipient,
    ));
  }
  else {
    watchdog('error', 'Unable to send email to %recipient', array(
      '%recipient' => $recipient,
    ));
  }
}