Home / Admin / Debug Load Email
Duplicate Snippet

Embed Snippet on Your Site

Debug Load Email

Test email on front page load and log error if occurred.

Code Preview
php
<?php
// Debug Load Email / Kiri Vadivelu / 2026 
add_action( 'template_redirect', 'page_load_email' );
function page_load_email() {
  
$to = "[email protected]"; // Replace with your email
$subject = 'wp_mail function test';
$message = 'This is a test of the wp_mail function: wp_mail is working';
$headers = '';
// Attempt to send the email
$sent_message = wp_mail( $to, $subject, $message, $headers );
// Display result
if ( $sent_message ) {
    echo 'The test message was sent. Check your email inbox.';
} else {
    echo 'The message was not sent!';
}
}   
add_action('wp_mail_failed', 'log_mailer_errors', 10, 1);
function log_mailer_errors( $wp_error ) {
    error_log( 'Mailer Error: ' . $wp_error->get_error_message() );
}   

Comments

Add a Comment