You are here

function gdpr_tasks_send_mail in General Data Protection Regulation 7

Helper function to send emails notifications to users.

Parameters

string $key: The email key to send.

GDPRTask $task: The wrapped ticket entity.

array $tokens: Optional array of tokens suitable for token_replace(). gdpr_task is be added automatically.

3 calls to gdpr_tasks_send_mail()
GdprTasksSarWorker::compile in modules/gdpr_tasks/src/Plugin/QueueWorker/GdprTasksSarWorker.php
Compile the SAR into a downloadable zip.
gdpr_tasks_request in modules/gdpr_tasks/gdpr_tasks.pages.inc
Request page for user.
gdpr_task_edit_gdpr_remove_form_submit in modules/gdpr_tasks/gdpr_tasks.admin.inc
Submit handler for removal tasks.

File

modules/gdpr_tasks/gdpr_tasks.module, line 705
Module file for the GDPR Tasks module.

Code

function gdpr_tasks_send_mail($key, GDPRTask $task, array $tokens = array()) {
  global $language;
  if (module_exists('i18n_variable') && i18n_variable_list('gdpr_tasks_emails')) {
    $emails = i18n_variable_get('gdpr_tasks_emails', $language->language, array());
  }
  else {
    $emails = variable_get('gdpr_tasks_emails', array());
  }

  // Allow other modules to alter the task emails.
  drupal_alter('gdpr_tasks_send_mail', $emails, $key, $task, $tokens);
  if (empty($emails[$key]['enabled'])) {
    return;
  }
  $email = $emails[$key];

  // Gather our params.
  $tokens['gdpr_task'] = $task;
  $params = array(
    'context' => array(
      'subject' => $email['subject'],
      'body' => check_markup($email['body']['value'], $email['body']['format'], $language->language, TRUE),
    ) + $tokens,
    'attachments' => NULL,
    'plaintext' => NULL,
  );
  $from = variable_get('gdpr_tasks_emails_from', NULL);
  $to = $task
    ->getOwner()->mail;
  drupal_mail('gdpr_tasks', 'gdpr_tasks_' . $key, $to, $language, $params, $from);
}