WordPress WooCommerce Email Logs: Setup Guide
This guide shows you how to set up email logging for your WordPress and WooCommerce site so you can see every email that gets sent, verify delivery, and troubleshoot issues like missing order notifications or password resets. You’ll learn both plugin-based and code-based methods, what to log, and how to read the logs. No coding experience is required for the plugin method, but the code snippet is included for those who prefer a lightweight approach.
What You’ll Need
- A WordPress site (self-hosted, not WordPress.com) with admin access.
- WooCommerce plugin installed and activated (if you want to log WooCommerce emails specifically).
- FTP or file manager access (for the code method).
- An email client or SMTP plugin if you plan to test sending (optional but helpful).
Step-by-Step
Method 1: Using a Plugin (Recommended)
- Install an email logging plugin. In your WordPress admin, go to Plugins → Add New and search for “WP Mail Logging” or “Email Log”. Choose a reputable plugin with good ratings and recent updates. Install and activate it.
- Configure the plugin settings. After activation, go to the plugin’s settings page (often under Settings → WP Mail Logging). Enable logging if it’s not on by default. You can usually choose to log all outgoing emails, and some plugins let you set a retention period (e.g., keep logs for 30 days). Set this according to your needs.
- Verify that logging is working. Trigger a test email. For example, go to WooCommerce → Settings → Emails and click “Send a test email” on any email type (like “New Order”). Or use the “Send Test Email” button in the plugin’s settings. Then check the plugin’s log page (usually under Tools → Email Log or a dedicated menu item). You should see the test email listed with details like recipient, subject, and timestamp.
- Check WooCommerce email logs specifically. WooCommerce emails are sent through the same WordPress mail function, so they will appear in the log automatically. To filter, use the plugin’s search or filter options to look for emails sent to customers or containing “WooCommerce” in the subject.
- Test a real order (optional). Place a test order on your site (you can use the “Cash on Delivery” payment method and then cancel it). Confirm that the “New Order” email appears in the log.
Method 2: Using a Code Snippet
- Add the logging function to your theme’s functions.php. Access your site files via FTP or the file manager in your hosting control panel. Open your active theme’s
functions.phpfile (or a custom plugin). Add the following code at the end:
add_action( 'wp_mail', 'log_wp_mail', 10, 1 );
function log_wp_mail( $args ) {
$log = 'Email Log ' . date('Y-m-d H:i:s') . "\n";
$log .= 'To: ' . implode(', ', $args['to']) . "\n";
$log .= 'Subject: ' . $args['subject'] . "\n";
$log .= 'Headers: ' . (is_array($args['headers']) ? implode(', ', $args['headers']) : $args['headers']) . "\n";
$log .= 'Message: ' . $args['message'] . "\n";
$log .= "-----------------------------------\n";
file_put_contents( WP_CONTENT_DIR . '/email-log.txt', $log, FILE_APPEND );
return $args;
}
- Save the file and test. After saving, send a test email (e.g., from WooCommerce settings). Then check the file
wp-content/email-log.txtvia FTP or file manager. You should see the email details logged. - Secure the log file (important). Make sure the log file is not publicly accessible. You can add a line to your
.htaccessfile to deny access to it, or move it outside the web root if possible. If you’re not comfortable with code, stick with the plugin method.
Common Mistakes
- Not checking the spam folder. Emails may be logged but still land in spam. Logging only shows that the email was sent, not that it was delivered to the inbox.
- Using an outdated plugin. Some email logging plugins are no longer maintained and may conflict with newer WordPress versions. Always choose a plugin with recent updates.
- Logging sensitive data. Email logs contain customer data and order details. If you keep logs for a long time, you might be storing personal data longer than necessary. Set a retention period.
- Forgetting to test after configuration. Just enabling logging isn’t enough; you must send a test email to confirm it works.
- Overwriting the log file. If you use the code method, make sure you use
FILE_APPEND(as shown) so you don’t overwrite previous logs.
Tips
- Use an SMTP plugin for reliable delivery. Email logging alone doesn’t fix delivery issues. If you notice emails not arriving, consider using an SMTP plugin (like WP Mail SMTP) to send emails through a proper SMTP server.
- Set up log rotation. Most plugins allow you to delete logs after a certain number of days. This keeps your database clean and avoids privacy issues.
- Combine with email testing. Use the log to see the exact content of emails. This helps when debugging HTML formatting issues in WooCommerce emails.
- Check the log after every major change. If you update WooCommerce or your theme, send a test email to ensure nothing broke.
- For developers, use a dedicated logging library. If you’re building a custom solution, consider using a library like Monolog to write structured logs.
Troubleshooting
No emails appear in the log. First, make sure you’ve actually triggered an email. If you’re testing WooCommerce, ensure that the email settings are enabled (some emails can be disabled in WooCommerce settings). Also, check if any other plugin is interfering with the mail function. Temporarily deactivate other mail-related plugins and try again.
The log file is empty (code method). Check file permissions. The web server needs write access to the wp-content directory. Also, ensure you added the code to the correct file (the active theme’s functions.php). If you’re using a child theme, add it to the child theme’s functions.php.
Emails are logged but not received. This is a delivery issue, not a logging issue. Check your spam folder, verify your domain’s SPF/DKIM records, or use an SMTP plugin to improve deliverability.
Logs are too large. If you’re using the code method, you’ll need to manually clean the file. With a plugin, set a retention period or manually delete old entries.
Plugin conflicts. If your site breaks after installing an email log plugin, deactivate it and check if the issue resolves. Some plugins may conflict with caching or security plugins.
Frequently Asked Questions
Will email logging slow down my site?
Minimal impact. Logging writes a small amount of data per email, which is negligible for most sites. However, if you have high traffic, consider using a plugin that stores logs efficiently.
Can I see the full content of the email in the log?
Yes, most plugins and the code method above log the full message body. This is useful for debugging formatting issues.
Do I need to log WooCommerce emails separately?
No. WooCommerce emails are sent through the standard WordPress mail function, so they will appear in the same log.
How long should I keep email logs?
It depends on your needs. For troubleshooting, 30 days is usually enough. For compliance, you may need longer, but be aware of privacy regulations like GDPR.
Can I export email logs?
Many plugins offer CSV export. If you’re using the code method, you can simply copy the text file.
Is there a way to test emails without sending real ones?
Some plugins allow you to “preview” emails, but to test logging, you need to actually send a test email. Use the test email feature in WooCommerce or the plugin.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.