The Mail Module provides comprehensive email monitoring, logging, and SMTP configuration for WordPress sites. It intercepts all emails sent via wp_mail(), records them to a custom database table with full metadata, and provides a WP_List_Table-based admin UI for browsing, searching, and managing email history.
Key Capabilities
Intercept and log all wp_mail() calls with full metadata (headers, attachments, backtrace)
Record delivery status (success/failure) with error messages
Capture CC, BCC, Reply-To headers and attachment details
Measure email delivery time (microsecond precision)
Main capture method. Extracts all email data from wp_mail() filter args, captures backtrace, categorizes email, logs to database. Returns args unchanged (filter passthrough).
extract_more_mail_info($phpmailer)
void
Hooks into PHPMailer instance to extract From, To, Subject, Body, ContentType, Attachments, MailHeader. Calculates delivery time via microtime. Updates existing log entry.
record_error($wp_error)
void
Records email failure status (0) and error message from WP_Error.
detect_content_type($content_type)
string
Detects HTML vs plain-text content and stores the flag. Returns content type unchanged.
categorize_email($subject, $message)
string
Auto-categorizes email based on keyword detection.
can_resend_email($subject, $message)
bool
Checks for time-sensitive keywords to determine if resend is safe.
get_attachment_locations($attachments)
array
Resolves attachment file paths to media library IDs, URLs, icons, and MIME types.
calculate_attachment_stats($attachments)
array
Returns ['count' => int, 'total_size' => int].
bp_record_mail(...)
void
Captures BuddyPress emails before wp_mail() fallback.
post_smtp_extract_from($log)
void
Extracts sender info from Post SMTP plugin objects.
4.2 ADVAN\Controllers\Mail_SMTP_Settings
Manages external SMTP provider configuration and email delivery routing.
Order matters:record_mail() fires first (as a wp_mail filter at PHP_INT_MAX), creating the initial database entry. Then extract_more_mail_info() fires later (via phpmailer_init) to enrich the record with additional PHPMailer data.
7. Email Categorization System
Emails are auto-categorized based on keyword detection in the subject and message body. The system checks in priority order, returning the first match:
Post SMTP plugin compatibility – extracts sender info.
post_smtp_on_failed
default
Post SMTP plugin failure handling.
admin_post_advan_mail_new
—
Handles compose form submission.
admin_post_resend_email
—
Handles email resend action.
12. SMTP Internals
The SMTP implementation uses WordPress’s bundled PHPMailer library. When SMTP settings are configured and the module is enabled, the plugin hooks into phpmailer_init at priority 999999 (intentionally very high to override other plugins).
Configuration Hierarchy
TEXT
wp_mail() called
│
└─ phpmailer_init action fires
│
├─ Priority 10-999998: Other plugins' PHPMailer hooks
│
├─ Priority 999999: Mail_SMTP_Settings::deliver_email_via_smtp()
│ ├── Validate settings (host + port required)
│ ├── Set isSMTP() mode
│ ├── Configure Host, Port, Auth, Encryption
│ ├── Set custom XMailer header
│ ├── Override From/FromName (if configured)
│ └── Apply SSL bypass (if enabled)
│
└─ Priority PHP_INT_MAX: WP_Mail_Log::extract_more_mail_info()
└── Extract enriched data for logging
WordPress Options (SMTP)
Option Key
Type
Description
advan_smtp_host
string
SMTP server hostname
advan_smtp_port
int
SMTP port (1–65535, default 587)
advan_encryption_type
string
'' (none), 'ssl', or 'tls'
advan_smtp_username
string
Auth username
advan_smtp_password
string
Auth password
advan_from_email
string
Override From address
advan_from_email_name
string
Override From display name
advan_smtp_bypass_ssl_verification
bool
Skip SSL certificate validation
13. Settings Reference
Settings are rendered using the plugin’s Settings::build_option() builder. The mail settings are on the Mail Options tab within the main settings page.
PHP
<?php
// Check if mail module is enabled$enabled = Settings::get_option( 'wp_mail_module_enabled' );
// Get the auto-clear schedule$schedule = Settings::get_option( 'advana_mail_logging_clear' );
// Get SMTP configuration$smtp_host = Settings::get_option( 'smtp_host' );
$smtp_port = Settings::get_option( 'smtp_port' );
// Check SMTP encryption type$encryption = Settings::get_option( 'encryption_type' );
Auto-Clear Cron Job
PHP
<?php
// Hook name for the auto-clear cron$hook = 'aadvana_mail_logging_clear';
// Callbackadd_action( 'aadvana_mail_logging_clear', [
WP_Mail_List::class,
'truncate_wp_mail_table'
]);
14. List Table Columns & Sorting
Columns
Key
Header
Sortable
Description
cb
☐
No
Bulk selection checkbox
time
Date
Yes ↑
Timestamp with Today/Yesterday formatting
email_to
To
Yes
Recipient address(es)
email_from
From
Yes
Sender address
email_cc
CC
Yes
Carbon-copy recipients
email_bcc
BCC
Yes
Blind carbon-copy recipients
email_reply_to
Reply-To
Yes
Reply-To address
subject
Subject
Yes
Email subject line
message_size
Size
Yes
Body size in bytes
email_category
Category
Yes
Auto-detected category with colored badge
is_html
Format
Yes
HTML or Text format indicator
attachments
Attachments
Yes
List of attached files
attachment_count
Att. Count
Yes
Number of attachments
delivery_time
Delivery Time
Yes
Send duration in milliseconds
plugin_slug
Plugin
Yes
Originating plugin/theme slug
Filter Views
View
Filter Criteria
All
No filter
Successful
status = 1
Unsuccessful
status = 0
HTML
is_html = 1
Text
is_html = 0
With attachments
Non-empty attachments JSON
Search
The search box performs full-text search across all columns. Input parameter: s.
15. Bulk & Row Actions
Row Actions (per mail entry)
Action
Method
Description
Details
REST API modal
Opens Thickbox modal with full email content and metadata via /aadvana/v1/mail_body/{id}/
Resend
admin_post_resend_email
Re-sends the email. Hidden for time-sensitive emails (can_resend = 0).
Delete
Admin page redirect
Permanently removes the log entry from the database
Bulk Actions
Action
Description
Delete
Delete all selected mail log entries
Security
Nonce verification for all form submissions
Capability check: manage_options required
Resend nonce: resend_email_{id} (unique per entry)
16. Third-Party Compatibility
BuddyPress
Full support via dedicated hooks:
bp_send_email — Captures BuddyPress emails before they’re routed
bp_email_use_wp_mail — Checks if BuddyPress falls back to wp_mail()
post_smtp_on_success — Extracts “From” address after successful Post SMTP delivery
post_smtp_on_failed — Extracts “From” address after Post SMTP failures
Note: When Post SMTP is active and managing email delivery, Advanced Analytics still captures the email details. However, the SMTP settings in Advanced Analytics should be disabled to avoid conflicts — let Post SMTP handle delivery while Advanced Analytics handles logging.
WooCommerce
WooCommerce emails sent via wp_mail() are automatically captured and categorized as order based on keyword detection in the subject/body.
17. Code Examples
Example 1: Check if Mail Module is Enabled
PHP
<?php
use ADVAN\Helpers\Settings;
$mail_enabled = Settings::get_option( 'wp_mail_module_enabled' );
if ( $mail_enabled ) {
// Mail module is active — emails are being logged
}
<?php
use ADVAN\Entities\WP_Mail_Entity;
// Get emails for blog ID 3$site_emails = WP_Mail_Entity::get_items([
'blog_id' => 3,
'per_page' => 25,
]);
echocount( $site_emails ) . ' emails from site #3';
Need User Guide documentation?
See Mails Module User Guide for more details about configuration, practical usage and information.