Full source code for the Simple Email Test plugin.
<?php
/*
Plugin Name: Simple Email Test
Plugin URI: https://webworkbench.co.uk
Description: A simple plugin to send test emails from WordPress.
Version: 1.0
Author: Tudor Gibson
License: GPL2
*/
if (!defined('ABSPATH')) {
exit;
}
add_action('admin_menu', 'set_add_admin_menu');
function set_add_admin_menu() {
add_management_page(
'Email Test',
'Email Test',
'manage_options',
'simple-email-test',
'set_email_test_page'
);
}
function set_email_test_page() {
$message = '';
if (
isset($_POST['set_send_email']) &&
check_admin_referer('set_email_test_nonce')
) {
$email = sanitize_email($_POST['set_test_email']);
if (is_email($email)) {
$subject = 'WordPress Email Test';
$body = 'Congratulations! Your WordPress email system is working correctly.';
$headers = array('Content-Type: text/plain; charset=UTF-8');
if (wp_mail($email, $subject, $body, $headers)) {
$message = 'Email sent successfully to ' . esc_html($email) . '.';
} else {
$message = 'Email failed to send.';
}
} else {
$message = 'Please enter a valid email address.';
}
}
echo '';
echo 'Email Test';
echo $message;
echo '';
wp_nonce_field('set_email_test_nonce');
echo '';
echo '';
echo 'Email Address';
echo '';
echo '';
echo '';
submit_button('Send Test Email', 'primary', 'set_send_email');
echo '';
echo '';
}