'', priority: 10 ); } /** * The address box, button, and result. * * @return void */ public function render(): void { ?>

get_error_message(); } } /** * AJAX: send it. * * @return void */ public function send(): void { check_ajax_referer( self::AJAX, 'nonce' ); if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error( array( 'message' => __( 'Sorry, you are not allowed to do that.', 'all-in-one-utilities' ) ), 403 ); } $to = isset( $_POST['to'] ) ? sanitize_email( wp_unslash( $_POST['to'] ) ) : ''; if ( ! is_email( $to ) ) { wp_send_json_error( array( 'message' => __( 'Please enter a valid email address.', 'all-in-one-utilities' ) ) ); } $site = wp_specialchars_decode( (string) get_option( 'blogname' ), ENT_QUOTES ); /* translators: %s: site name */ $subject = sprintf( __( '[%s] Test email', 'all-in-one-utilities' ), $site ); $body = '

' . sprintf( /* translators: 1: site name, 2: date and time */ esc_html__( 'This is a test email from %1$s, sent %2$s. If you can read it, your site can send email.', 'all-in-one-utilities' ), esc_html( $site ), esc_html( wp_date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ) ) ) ) . '

'; add_action( 'wp_mail_failed', array( self::class, 'capture_error' ) ); $sent = wp_mail( $to, $subject, Email::layout( $body, $subject ), array( 'Content-Type: text/html; charset=UTF-8' ) ); if ( $sent ) { wp_send_json_success( array( /* translators: %s: email address */ 'message' => sprintf( __( 'Sent to %s. If it doesn\'t arrive within a few minutes, check the spam folder; if it\'s not there either, your host may be blocking email, and an SMTP service is the usual fix.', 'all-in-one-utilities' ), $to ), ) ); } wp_send_json_error( array( /* translators: %s: error message */ 'message' => sprintf( __( 'WordPress couldn\'t send it: %s', 'all-in-one-utilities' ), '' === self::$error ? __( 'no reason given', 'all-in-one-utilities' ) : self::$error ), ) ); } }