You are here

function purge_users_send_notification_email in Auto Purge Users 8

Same name and namespace in other branches
  1. 8.3 purge_users.module \purge_users_send_notification_email()
  2. 8.2 purge_users.module \purge_users_send_notification_email()

Send notification email.

2 calls to purge_users_send_notification_email()
BatchWorker::batchworkerpurgeusers in src/Plugin/BatchWorker/BatchWorker.php
Process items in a batch.
PurgeUsersQueueWorker::processItem in src/Plugin/QueueWorker/PurgeUsersQueueWorker.php
Works on a single queue item.

File

./purge_users.module, line 243
Purge users module file.

Code

function purge_users_send_notification_email($account) {

  // Email to be sent to this Email ID.
  $mailManager = \Drupal::service('plugin.manager.mail');
  $module = 'purge_users';
  $key = 'delete_users';
  $to = $account
    ->get('mail')->value;
  $config = \Drupal::config('purge_users.settings');
  $message = $config
    ->get('inactive_user_notify_text');
  $moduleHandler = \Drupal::service('module_handler');
  if ($moduleHandler
    ->moduleExists('token')) {
    $token_service = \Drupal::token();
    $message = $token_service
      ->replace($message, array(
      'user' => $account,
    ));
  }
  $params = [
    'subject' => t('Your account is deleted.'),
    'body' => $message,
  ];
  $langcode = $account
    ->getPreferredLangcode();
  $send = TRUE;
  $mailManager
    ->mail($module, $key, $to, $langcode, $params, NULL, $send);
}