You are here

function development_environment_mail_alter in Development Environment 7

Same name and namespace in other branches
  1. 8 development_environment.module \development_environment_mail_alter()

Implements hook_mail_alter().

File

./development_environment.module, line 70
Holds hooks for the Development Environment module.

Code

function development_environment_mail_alter(&$message) {
  $log_emails = variable_get('development_environment.log_emails', FALSE);
  if ($log_emails) {

    // Stop emails from being sent.
    $message['send'] = FALSE;
    $lid = db_insert('development_environment_log')
      ->fields([
      'email_data' => serialize($message),
      'timestamp' => REQUEST_TIME,
      'recipient_email' => $message['to'],
      'subject' => $message['subject'],
    ])
      ->execute();
    if (user_access('access development environment email logs')) {
      drupal_set_message(t('The email to @email was not sent, as this is a development environment. The mail details can be viewed in the !log.', array(
        '@email' => $message['to'],
        '!log' => l(t('log'), 'admin/reports/email_log/' . $lid),
      )));
    }
    else {
      drupal_set_message(t('The email to @email was not sent, as this is a development environment', [
        '@email' => $message['to'],
      ]));
    }
  }
}