wp_get_environment_type, in core at last

WordPress had no concept of an environment, so every site invented one — and the versions differed enough that a shared plugin could not rely on any of them.

// wp-config.php
define( 'WP_ENVIRONMENT_TYPE', getenv( 'APP_ENV' ) ?: 'production' );

// anywhere
if ( 'production' !== wp_get_environment_type() ) {
    add_filter( 'wp_mail', 'turkerdev_redirect_all_mail' );
}

// the accepted values: production, staging, development, local
// anything else falls back to production

Defaulting to production when nothing is set is the correct choice and is what stops a misconfigured host turning on debug output. The value can also come from an environment variable of the same name without the constant, which is what makes it work on a platform that injects them. The four accepted values are fixed, so a site with a qa environment has to map it — and mapping it to staging is better than inventing a fifth.