# "Confirm Email" Field for Contact Form 7

> Makes visitors type their email twice and shows an error when the two addresses do not match, so you do not lose replies to typos.

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

## Code

```php
$wpide_cf7_email_field   = 'your-email';
$wpide_cf7_confirm_field = 'your-email-confirm';

$wpide_cf7_confirm_check = function ( $result, $tag ) use ( $wpide_cf7_email_field, $wpide_cf7_confirm_field ) {
    if ( $tag->name !== $wpide_cf7_confirm_field ) {
        return $result;
    }

    $email   = isset( $_POST[ $wpide_cf7_email_field ] ) ? strtolower( trim( (string) wp_unslash( $_POST[ $wpide_cf7_email_field ] ) ) ) : '';
    $confirm = isset( $_POST[ $wpide_cf7_confirm_field ] ) ? strtolower( trim( (string) wp_unslash( $_POST[ $wpide_cf7_confirm_field ] ) ) ) : '';

    if ( $email !== $confirm ) {
        $result->invalidate( $tag, 'The email addresses do not match.' );
    }

    return $result;
};

add_filter( 'wpcf7_validate_email', $wpide_cf7_confirm_check, 20, 2 );
add_filter( 'wpcf7_validate_email*', $wpide_cf7_confirm_check, 20, 2 );
```

## Notes

Add a second email field named your-email-confirm to the form, for example [email* your-email-confirm], or change the names at the top.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find ""Confirm Email" Field for Contact Form 7" 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/
