Skip to content

Instantly share code, notes, and snippets.

@mohamedrez
Last active August 29, 2015 14:04
Show Gist options
  • Save mohamedrez/76580b56ee823b7a5196 to your computer and use it in GitHub Desktop.
Save mohamedrez/76580b56ee823b7a5196 to your computer and use it in GitHub Desktop.
<?php
/**
* Logs error to file
*
* @uses `error_log` function to log on file
*
* @param string $error message of the error
* @param string $type type of the error message
*/
function log_error( $error, $type = 'error' ) {
$path = dirname( __FILE__ ) . '/mail_log.txt';
$msg = sprintf( "[%s][%s] %s\n", date( 'd.m.Y h:i:s' ), $type, $error );
error_log( $msg, 3, $path );
}
/**
* Log the mail to text file
*
* @uses `wp_mail` filter
* @param array $mail
*/
function wedevs_mail_log( $mail ) {
$message = "to: {$mail['to']} \nsub: {$mail['subject']}, \nmsg:{$mail['message']}";
log_error( 'mail', $message );
return $mail;
}
add_filter( 'wp_mail', 'wedevs_mail_log', 10 );
// special thnx to http://tareq.wedevs.com/2012/03/log-wordpress-outgoing-mails-for-debugging/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment