# Send Contact Form 7 Emails From Your Own Domain

> When a Contact Form 7 form is set to send "from" the visitor's address, switches the sender to your own domain and moves the visitor's address to Reply-To, so emails stop landing in spam.

- Type: PHP
- Runs: Run everywhere
- Category: [Forms](https://wpide.com/library/category/forms/)
- Tags: contact-form-7, deliverability, email
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/cf7-sender-on-own-domain/

## Code

```php
$wpide_cf7_sender = ''; // e.g. 'Website <hello@yourdomain.com>'; empty = wordpress@yourdomain.

add_filter( 'wpcf7_mail_components', function ( $components ) use ( $wpide_cf7_sender ) {
    $site = preg_replace( '/^www\./', '', (string) wp_parse_url( home_url(), PHP_URL_HOST ) );

    if ( ! preg_match( '/([^<\s]+@[^>\s]+)/', (string) $components['sender'], $m ) ) {
        return $components;
    }

    $address = strtolower( $m[1] );
    $domain  = (string) substr( strrchr( $address, '@' ), 1 );

    if ( '' === $site || $domain === $site || substr( $domain, -strlen( '.' . $site ) ) === '.' . $site ) {
        return $components;
    }

    if ( false === stripos( (string) $components['additional_headers'], 'Reply-To:' ) && is_email( $address ) ) {
        $components['additional_headers'] = trim( $components['additional_headers'] . "\nReply-To: " . $address );
    }

    $components['sender'] = $wpide_cf7_sender ? $wpide_cf7_sender : wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ) . ' <wordpress@' . $site . '>';

    return $components;
} );
```

## Notes

Set the sender address at the top or leave it empty to use wordpress@ your domain; replying still goes to the visitor.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Send Contact Form 7 Emails From Your Own Domain" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
