defined( 'WPMS_PLUGIN_VER' ), 'FluentSMTP' => defined( 'FLUENTMAIL' ) || defined( 'FLUENTMAIL_PLUGIN_VERSION' ), 'Post SMTP' => defined( 'POST_SMTP_VER' ), 'Easy WP SMTP' => defined( 'EasyWPSMTP_PLUGIN_VERSION' ) || class_exists( 'EasyWPSMTP' ), 'SMTP Mailer' => class_exists( 'SMTP_MAILER' ), 'Brevo' => class_exists( 'SIB_Manager' ), 'Site Mailer' => defined( 'SITE_MAILER_VERSION' ), 'Gravity SMTP' => defined( 'GRAVITY_SMTP_VERSION' ), 'ALPEG Mail' => defined( 'ALPEG_MAIL_VERSION' ), ); foreach ( $known as $name => $active ) { if ( $active ) { return $name; } } if ( has_action( 'phpmailer_init' ) || has_filter( 'pre_wp_mail' ) ) { return 'other'; } return ''; } /** * Last recorded mail error. * * @return array|null time, message. */ public static function last_error() { $e = get_option( 'alpeg_forms_last_mail_error' ); return is_array( $e ) && ! empty( $e['message'] ) ? $e : null; } /** * Number of entries in the last 7 days whose notification failed. * * @return int */ public static function recent_failures() { return Entries::count( array( 'mail_status' => 'failed', 'after' => gmdate( 'Y-m-d H:i:s', time() - 7 * DAY_IN_SECONDS ), ) ); } /** * Handle the "send test mail" form (admin-post). */ public static function handle_test() { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'You are not allowed to do this.', 'alpeg-forms' ), 403 ); } check_admin_referer( 'alpeg_forms_testmail' ); $to = isset( $_POST['af_test_to'] ) ? sanitize_email( wp_unslash( $_POST['af_test_to'] ) ) : ''; if ( ! is_email( $to ) ) { $notice = array( 'type' => 'error', 'message' => __( 'Please enter a valid email address.', 'alpeg-forms' ), ); } else { $r = Mailer::test( $to ); if ( $r['ok'] ) { delete_option( 'alpeg_forms_last_mail_error' ); $notice = array( 'type' => 'success', /* translators: %s: email address */ 'message' => sprintf( __( 'The test mail was handed over to the mail server for %s. Please check your inbox and spam folder.', 'alpeg-forms' ), $to ), ); } else { $notice = array( 'type' => 'error', /* translators: %s: error message */ 'message' => sprintf( __( 'The test mail could not be sent: %s', 'alpeg-forms' ), $r['error'] ), ); } } set_transient( 'alpeg_forms_settings_notice_' . get_current_user_id(), $notice, 60 ); wp_safe_redirect( admin_url( 'admin.php?page=alpeg-forms-settings#mail' ) ); exit; } }