You are here

function mail_logger_mail_alter in Mail Logger 6

Same name and namespace in other branches
  1. 5 mail_logger.module \mail_logger_mail_alter()
  2. 7 mail_logger.module \mail_logger_mail_alter()

Implementation of hook_mail_alter().

Purpose of this function is to log all outgoing mail

File

./mail_logger.module, line 98
Mail Logger module logs all outgoing mail that passes through the drupal_mail function.

Code

function mail_logger_mail_alter($message) {
  $message['body'] = is_array($message['body']) ? drupal_wrap_mail(implode("\n\n", $message['body'])) : drupal_wrap_mail($message['body']);
  $message['date_sent'] = time();
  $record = array(
    'mailkey' => $message['id'],
    'mail_to' => $message['to'],
    'subject' => $message['subject'],
    'body' => $message['body'],
    'mail_from' => $message['from'],
    'headers' => serialize($message['headers']),
    'date_sent' => $message['date_sent'],
    'language' => $message['language']->language,
  );
  drupal_write_record('mail_logger', $record);

  // Fire 'mail_logger' 'mail_sent' action.
  module_invoke_all('mail_logger', 'mail_sent', $message, mail_logger_email_user($message['from']), mail_logger_email_user($message['to']));
}