403 ) ); } if ( ! isset( $_POST['ps_mail_test_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['ps_mail_test_nonce'] ) ), 'ps_mail_test' ) ) { wp_die( esc_html__( 'Security check failed.', 'peptide-starter' ), '', array( 'response' => 403 ) ); } $to = isset( $_POST['to'] ) ? sanitize_email( wp_unslash( $_POST['to'] ) ) : ''; if ( ! is_email( $to ) ) { wp_safe_redirect( admin_url( 'tools.php?page=ps-mail-test' ) ); exit; } $captured_error = ''; $capture = function ( $wp_error ) use ( &$captured_error ) { if ( is_wp_error( $wp_error ) ) { $captured_error = $wp_error->get_error_message(); } }; add_action( 'wp_mail_failed', $capture ); $start = microtime( true ); $subject = sprintf( /* translators: %s: site name */ __( '[%s] Mail deliverability test', 'peptide-starter' ), wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ) ); $body = sprintf( /* translators: %s: site url */ __( "This is a wp_mail deliverability test from %s.\n\nIf you received this, wp_mail is working.", 'peptide-starter' ), home_url( '/' ) ); $sent = wp_mail( $to, $subject, $body ); $elapsed = ( microtime( true ) - $start ) * 1000; remove_action( 'wp_mail_failed', $capture ); set_transient( 'ps_mail_test_result', array( 'sent' => (bool) $sent, 'to' => $to, 'ms' => (int) $elapsed, 'error' => (string) $captured_error, ), 60 ); wp_safe_redirect( admin_url( 'tools.php?page=ps-mail-test' ) ); exit; } add_action( 'admin_post_ps_mail_test', 'peptide_starter_mail_diagnostic_send' );