You are here

function notify_mail in Notify 8

Same name and namespace in other branches
  1. 6 notify.module \notify_mail()
  2. 7 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 118
Notify module sends e-mail digests of new content and comments.

Code

function notify_mail($key, &$message, $params) {
  $config = \Drupal::config('notify.settings');
  $siteconfig = \Drupal::config('system.site');
  $username = $params['user']
    ->getDisplayName();
  $useruid = $params['user']->uid;
  $viewmode = $params['viewmode'];
  $sitename = $siteconfig
    ->get('name');
  $sitemail = $siteconfig
    ->get('mail');
  $upl = $params['user']
    ->getPreferredLangcode();
  $messagefrom = $sitename . ' <' . $sitemail . '>';
  $message['headers']['MIME-Version'] = '1.0';
  $message['headers']['Content-Type'] = 'text/html;charset=utf-8';
  $message['headers']['From'] = $message['headers']['Sender'] = $message['headers']['Errors-To'] = $message['headers']['Reply-to'] = $messagefrom;
  $message['headers']['Return-Path'] = $sitemail;
  $message['subject'] = t('New content notification for @username from @sitename', array(
    '@username' => $username,
    '@sitename' => $sitename,
  ), array(
    'langcode' => $upl,
  ));
  $message['body'][] = Markup::create(t('Greetings @user,', array(
    '@user' => $username,
  ), array(
    'langcode' => $upl,
  )) . '<br /><br />');
  $message['body'][] = Markup::create(t('this is a notification about new content from @sitename.', array(
    '@sitename' => $sitename,
  ), array(
    'langcode' => $upl,
  )) . '<br />');
  $fulltext = t('Click on the links below to see the whole node/comment.', array(), array(
    'langcode' => $upl,
  ));
  if (0 == $viewmode) {
    $message['body'][] = t('This e-mail only lists the titles.', array(), array(
      'langcode' => $upl,
    )) . ' ' . $fulltext;
  }
  elseif (1 == $viewmode) {
    $message['body'][] = t('This e-mail may only shows excerpts.', array(), array(
      'langcode' => $upl,
    )) . ' ' . $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,
    ));
  }
  $message['body'][] = Markup::create($params['content']);
  $message['body'][] = Markup::create("-- <br />" . t('This is an automatic e-mail from @sitename.', array(
    '@sitename' => $siteconfig
      ->get('name'),
  ), array(
    'langcode' => $upl,
  )));
}