You are here

function _birthdays_send_admin_message in Birthdays 6

Same name and namespace in other branches
  1. 5 birthdays.module \_birthdays_send_admin_message()

Sends an e-mail to administrator for the upcoming day(s).

1 call to _birthdays_send_admin_message()
birthdays_cron in ./birthdays.module
Implementation of hook_cron().

File

./birthdays.mail.inc, line 61
This file contains the files necessary to e-mail the administrator his periodical listings and/or the users on their birthday.

Code

function _birthdays_send_admin_message($days = 1) {
  global $user;

  // Only proceed when admin messages are enabled
  if (variable_get('birthdays_remind', BIRTHDAYS_ADMIN_MAIL_DISABLED) != BIRTHDAYS_ADMIN_MAIL_DISABLED) {

    // Get birthdays
    $accounts = birthdays_get_birthdays_by_days($days);

    // If there were any users:
    if (count($accounts) > 0) {

      // Get site e-mail to send reminder to and from
      $to = variable_get('site_mail', ini_get('sendmail_from'));

      // Load the accounts into the parameters;
      $params['accounts'] = $accounts;
      $params['period'] = variable_get('birthdays_remind', BIRTHDAYS_ADMIN_MAIL_DISABLED);

      // Send the mail
      drupal_mail('birthdays', 'admin_message', $to, user_preferred_language($user), $params);

      // Log action
      watchdog('Birthdays', 'Sent birthday overview e-mail to admin.', array(), WATCHDOG_NOTICE, ' ');
    }
  }
}