function birthdays_mail in Birthdays 7
Same name and namespace in other branches
- 6 birthdays.mail.inc \birthdays_mail()
Implements hook_mail().
File
- ./
birthdays.module, line 1128 - The Birthdays module allows users to add their birthday to their profile. It lists birthdays on a seperate page and in different blocks. Users can receive an email on their birthday automatically, and the administrator can receive daily reminders of…
Code
function birthdays_mail($key, &$message, $params) {
switch ($key) {
case 'admin_mail':
$message['subject'] = t('Upcoming birthdays');
foreach ($params as $category => $items) {
$type = $items['instance']['entity_type'];
// Category header, underlined.
$message['body'][] = $category;
$message['body'][] = str_repeat('-', drupal_strlen($category));
$message['body'][] = '';
foreach ($items['entities'] as $entity) {
$item = array();
// Entity label.
$label = entity_label($type, $entity);
if ($label) {
$item[] = $label;
}
// Actual birthday and age.
$date = reset(field_get_items($type, $entity, $items['instance']['field_name']));
$birthday = BirthdaysBirthday::fromArray($date);
$item[] = $birthday
->toString('Y/m/d', 'M d') . ' (' . $birthday
->getAge() . ')';
// Entity URL.
$uri = entity_uri($type, $entity);
if ($uri) {
$item[] = url($uri['path'], array(
'absolute' => TRUE,
) + $uri['options']);
}
$message['body'][] = join($item, ', ');
}
$message['body'][] = '';
}
break;
}
}