// create logs
function create_wp_email_logs($args)
{
if (empty($args)) {
return;
}

// Define the path to the log file
$log_file = plugin_dir_path(__FILE__) . 'mae-mail-log.txt';

// Retrieve the current date and time
$datetime = date('Y-m-d H:i:s');

// Prepare the log entry as a plain text with key-value pairs
$log_entry = "Datetime: $datetime\n";
$log_entry .= "Content: " . print_r($args, true) . "\n";
$log_entry .= "\n";

// Write the log entry to the file
if (file_put_contents($log_file, $log_entry, FILE_APPEND) === false) {
error_log('Failed to write to log file: ' . $log_file);
}
}
// Hook into wp_mail filter to log email details
function log_wp_mail_args($args)
{
// create logs
create_wp_email_logs($args);

return $args;
}
add_filter('wp_mail', 'log_wp_mail_args', 10, 1);