You are here

function notify_mail in Notify 7

Same name and namespace in other branches
  1. 8 notify.module \notify_mail()
  2. 6 notify.module \notify_mail()
  3. 2.0.x notify.module \notify_mail()
  4. 1.0.x notify.module \notify_mail()

Implements hook_mail().

File

./notify.module, line 221
Notify module sends e-mail digests of new content and comments.

Code

function notify_mail($key, &$message, $params) {
  $username = format_username($params['user']);
  $useruid = $params['user']->uid;
  $viewmode = $params['viewmode'];
  $sitename = variable_get('site_name', 'Drupal');
  $upl = user_preferred_language($params['user']);
  $message['headers']['MIME-Version'] = '1.0';
  $message['headers']['Content-Type'] = 'text/plain;charset=utf-8';
  $message['subject'] = t('New content notification for !username from !sitename', array(
    '!username' => $username,
    '!sitename' => $sitename,
  ), array(
    'langcode' => $upl->language,
  ));
  $message['body'][] = t('Greetings !user, this is a notification about new content from !sitename.', array(
    '!user' => $username,
    '!sitename' => $sitename,
  ), array(
    'langcode' => $upl->language,
  ));
  $fulltext = t('Click on the links below to see the whole node/comment.', array(), array(
    'langcode' => $upl->language,
  ));
  if (0 == $viewmode) {
    $message['body'][] = t('This e-mail only lists the titles.', array(), array(
      'langcode' => $upl->language,
    )) . ' ' . $fulltext;
  }
  elseif (1 == $viewmode) {
    $message['body'][] = t('This e-mail may only shows excerpts.', array(), array(
      'langcode' => $upl->language,
    )) . ' ' . $fulltext;
  }
  else {
    $message['body'][] = t('The full text is included in this e-mail, but to see the original node, you can click on the links below.', array(), array(
      'langcode' => $upl->language,
    ));
  }
  $message['body'][] = $params['content'];
  $message['body'][] = "-- \n" . t('This is an automatic e-mail from !sitename.', array(
    '!sitename' => variable_get('site_name', 'Drupal'),
  ), array(
    'langcode' => $upl->language,
  )) . "\n" . t('To stop receiving these e-mails, change your notification preferences at !notify-url', array(
    '!notify-url' => url('user/' . $useruid . '/notify', array(
      'absolute' => TRUE,
    )),
  ), array(
    'langcode' => $upl->language,
  ));
}