Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: Log Emails for Debugging
- Plugin URI: http://www.damiencarbery.com
- Description: Log emails sent.
- Author: Damien Carbery
- Version: 0.4
- $Id: wp-mail-logging.php 3641 2016-04-15 17:48:53Z damien $
- */
- add_filter( 'wp_mail', 'dbg_log_email_info' );
- function dbg_log_email_info( $params )
- {
- // If $params['to'] email is an array then implode it into a string.
- if (is_array($params['to'])) {
- $to = implode(', ', $params['to']);
- }
- else {
- $to = $params['to'];
- }
- $log_info = sprintf('To: %s | Subject: %s | Message: %s | Headers: %s', $to, $params['subject'], var_export($params['message'], true), var_export($params['headers'], true));
- // Write to/from/subject of email to a log.
- if (function_exists('debug2log')) {
- debug2log($log_info);
- }
- else {
- error_log($log_info);
- }
- return $params;
- }
- // From email address is not sent in 'wp_mail' filter so log it via another filter.
- add_filter( 'wp_mail_from', 'dbg_log_email_from' );
- function dbg_log_email_from( $from ) {
- if (function_exists('debug2log')) {
- debug2log(sprintf('Email from:%s', $from));
- }
- else {
- error_log(sprintf('Email from:%s', $from));
- }
- return $from;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement