You are here

function patron_email_form_submit in Library 6

Same name and namespace in other branches
  1. 5.2 patron/patron.pages.inc \patron_email_form_submit()

File

patron/patron.pages.inc, line 84
Functions for generating page displays related to the patron module

Code

function patron_email_form_submit($form, &$form_state) {
  $values = $form_state['values'];
  if ($values['to']) {
    $to = $values['to'];
    $recipients = $values['patron'];
  }
  else {
    $patrons = patron_get_patrons();
    $to_array = array();
    $recipient_array = array();
    foreach ($patrons as $patron) {
      $to_array[] = $patron->email;
      $recipient_array[] = $patron->name_first . ' ' . $patron->name_last;
    }
    $to = implode(',', $to_array);
    $recipients = implode(', ', $recipient_array);
  }
  if (drupal_mail('patron', 'email_form', $to, language_default(), $values)) {
    watchdog('library', 'Sent email to %recipient', array(
      '%recipient' => $recipients,
    ));
    drupal_set_message(t('Your message has been sent to ' . $recipients));
  }
  else {
    watchdog('error', 'Unable to send email to %recipient', array(
      '%recipient' => $recipients,
    ));
  }
  return;
}