# Advanced Email Tester (WordPress Plugin)
A comprehensive WordPress plugin for testing and debugging email functionality. Provides detailed logging, SMTP testing, interactive admin interface, and error capture capabilities for troubleshooting WordPress email issues.
Purpose
WordPress email issues are notoriously difficult to debug. This plugin provides:
- Send test emails with detailed results
- SMTP configuration testing
- Email logging with full details
- Error capture from PHPMailer
- Export capabilities for support tickets
Core Features
Custom Logging Table
php
function create_log_table() {
global $wpdb;
$charset_collate = $wpdb->get_charset_collate();
$sql = "CREATE TABLE {$wpdb->prefix}email_test_logs (
id bigint(20) NOT NULL AUTO_INCREMENT,
sent_to varchar(100) NOT NULL,
subject varchar(255) NOT NULL,
body longtext NOT NULL,
headers text,
attachments text,
status varchar(20) NOT NULL,
error_message text,
phpmailer_error text,
smtp_debug text,
sent_at datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
PRIMARY KEY (id),
KEY sent_to (sent_to),
KEY status (status),
KEY sent_at (sent_at)
) $charset_collate;";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
}Test Email Sending
php
function handle_test_email() {
check_ajax_referer('aet_nonce', 'security');
$to = sanitize_email($_POST['to']);
$subject = sanitize_text_field($_POST['subject']);
$body = wp_kses_post($_POST['body']);
$headers = [];
if (!empty($_POST['from_email'])) {
$headers['From'] = sanitize_email($_POST['from_email']);
}
if (!empty($_POST['reply_to'])) {
$headers['Reply-To'] = sanitize_email($_POST['reply_to']);
}
$result = wp_mail($to, $subject, $body, $headers);
// Log the result
$this->log_email($to, $subject, $body, $headers, $result);
wp_send_json(['success' => $result]);
}PHPMailer Error Capture
php
function capture_phpmailer_errors($phpmailer) {
add_action('wp_mail_failed', array($this, 'capture_mail_error'));
}
function capture_mail_error($wp_error) {
global $phpmailer;
if (isset($phpmailer) && !empty($phpmailer->ErrorInfo)) {
$this->phpmailer_error = sanitize_text_field($phpmailer->ErrorInfo);
}
}Admin Interface
php
function render_admin_page() {
?>
<div class="wrap">
<h1>Advanced Email Tester</h1>
<div class="aet-tabs">
<button class="tab-btn active" data-tab="send">Send Test</button>
<button class="tab-btn" data-tab="settings">SMTP Settings</button>
<button class="tab-btn" data-tab="logs">Email Logs</button>
</div>
<div id="aet-send-tab" class="tab-content">
<form id="aet-send-form">
<table class="form-table">
<tr>
<th>To (Email)</th>
<td><input type="email" name="to" required class="regular-text"></td>
</tr>
<tr>
<th>Subject</th>
<td><input type="text" name="subject" value="Test Email" required class="regular-text"></td>
</tr>
<tr>
<th>Message</th>
<td><textarea name="body" rows="5" class="large-text">This is a test email from Advanced Email Tester.</textarea></td>
</tr>
</table>
<button type="submit" class="button button-primary">Send Test</button>
</form>
</div>
<div id="aet-logs-tab" class="tab-content" style="display:none;">
<?php echo $this->render_logs_table(); ?>
</div>
</div>
<?php
}Technical Details
| Feature | Implementation |
|---|---|
| Database | Custom table for logs |
| AJAX | Test sending, log management |
| PHPMailer | Error capture hook |
| Export | CSV export of logs |
| Pagination | Configurable per page |
Version
- 1.2.2 - Current stable version
- Tested up to WordPress 6.4
- Requires PHP 7.4+
Architecture Feedback
Spotted a potential optimization or antipattern? Let me know.