groundhogg/email/to

📅 Published on

📝 Last updated

Documentation

»

Filter Hooks

»

groundhogg/email/to

Filters the To email address just before a message is sent. Use this to redirect emails — for example, to route all sends through a test inbox in staging environments.

apply_filters( 'groundhogg/email/to', $to, $contact, $email );

You will receive the recipient email address string, the Contact object, and the Email object.

Example

add_filter( 'groundhogg/email/to', 'my_extension_redirect_in_staging', 10, 3 );

/**
 * Redirect all emails to a test inbox on staging.
 *
 * @param string               $to
 * @param \Groundhogg\Contact $contact
 * @param \Groundhogg\Email   $email
 *
 * @return string
 */
function my_extension_redirect_in_staging( $to, $contact, $email ) {
    if ( defined( 'WP_ENV' ) && WP_ENV === 'staging' ) {
        return 'staging-inbox@example.com';
    }

    return $to;
}

Was this helpful?

Let us know if this document answered your question. That’s the only way we can improve.