false, 'message' => __( 'Routing through SendFleet is off or no API key is saved, so the test was not sent.', 'sendfleet' ), ); } $captured = array(); $failure = null; $on_dispatch = static function ( $results ) use ( &$captured ) { $captured = (array) $results; }; $on_failure = static function ( $error ) use ( &$failure ) { $failure = $error; }; add_action( 'sendfleet_dispatched', $on_dispatch ); add_action( 'wp_mail_failed', $on_failure ); Dispatcher::$force_immediate = true; $headers = array( 'Content-Type: text/html; charset=UTF-8' ); if ( '' !== $from && is_email( $from ) ) { $headers[] = 'From: ' . $from; } $site = wp_specialchars_decode( (string) get_bloginfo( 'name' ), ENT_QUOTES ); /* translators: %s: site title. */ $subject = sprintf( __( 'SendFleet test email from %s', 'sendfleet' ), $site ); $sent = wp_mail( $to, $subject, self::html( $site ), $headers ); Dispatcher::$force_immediate = false; remove_action( 'sendfleet_dispatched', $on_dispatch ); remove_action( 'wp_mail_failed', $on_failure ); $result = isset( $captured[0] ) ? $captured[0] : null; if ( $sent && $result && Log::STATUS_ACCEPTED === $result['status'] ) { return array( 'ok' => true, 'message' => sprintf( /* translators: 1: recipient, 2: sending mode, 3: message id. */ __( 'SendFleet accepted the test email to %1$s (mode: %2$s, message id: %3$s). Delivery is asynchronous; check the inbox in a minute.', 'sendfleet' ), $result['email'], '' !== $result['mode'] ? $result['mode'] : '—', '' !== $result['message_id'] ? $result['message_id'] : '—' ), ); } if ( $sent && $result && Log::STATUS_QUEUED === $result['status'] ) { return array( 'ok' => true, 'message' => sprintf( /* translators: 1: recipient, 2: reason. */ __( 'The test email to %1$s is queued and will be retried automatically: %2$s', 'sendfleet' ), $result['email'], $result['detail'] ), ); } if ( $sent && $result && Log::STATUS_FALLBACK === $result['status'] ) { return array( 'ok' => false, /* translators: %s: reason. */ 'message' => sprintf( __( 'SendFleet did not accept the test email; it was sent through WordPress\' default mailer instead (fallback). %s', 'sendfleet' ), $result['detail'] ), ); } if ( $result ) { return array( 'ok' => false, 'message' => sprintf( /* translators: 1: error code, 2: error detail. */ __( 'Not sent (%1$s): %2$s', 'sendfleet' ), '' !== $result['code'] ? $result['code'] : $result['status'], $result['detail'] ), ); } return array( 'ok' => false, 'message' => is_wp_error( $failure ) ? $failure->get_error_message() : __( 'The test email could not be sent.', 'sendfleet' ), ); } /** * The test email body. * * @param string $site Site title. * @return string */ private static function html( $site ) { $time = wp_date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ) ); return '
' . '' . '| ' . ' |