You are here

function regcode_mailer_mail_action in Registration codes 6.2

Same name and namespace in other branches
  1. 7.2 regcode_mailer/regcode_mailer.module \regcode_mailer_mail_action()
  2. 7 regcode_mailer/regcode_mailer.module \regcode_mailer_mail_action()

Implements the mail action

1 string reference to 'regcode_mailer_mail_action'
regcode_views_default_views in ./regcode.views_default.inc
Implements hook_views_default_views().

File

regcode_mailer/regcode_mailer.module, line 102

Code

function regcode_mailer_mail_action(&$object, &$context = array()) {
  static $i = 0;

  // Check we have enough emails for this action
  if (!isset($context['emails'][$i])) {
    drupal_set_message(t('Ran out of emails, unable to send code (%code).', array(
      '%code' => $object->code,
    )));
    return FALSE;
  }

  // Params for the email
  $params = array(
    'regcode' => $object,
    'message' => $context['message'],
    'subject' => $context['subject'],
  );

  // Send
  $email = $context['emails'][$i];
  $message = drupal_mail('regcode_mailer', 'regcode', $email, language_default(), $params);
  drupal_set_message(t("Sent message with code %code to %email", array(
    '%code' => $object->code,
    '%email' => $email,
  )));

  // Update the database
  db_query('INSERT INTO {regcode_mailer} (rid, mailed, recipient) VALUES (%d, %d, "%s")', $object->rid, time(), $email);

  // Tag the code
  foreach ($context['terms'] as $term_id) {
    db_query('REPLACE INTO {regcode_term} (rid, tid) VALUES (%d, %d)', $object->rid, $term_id);
  }
  $i++;
}