# Sequential Reference Number Mail Tag for Contact Form 7

> Adds a [_wpide_ref] mail tag that gives every Contact Form 7 submission a running reference number like WEB-1042, which you can quote in the subject or autoresponder.

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

## Code

```php
$wpide_cf7_ref_prefix = 'WEB-';
$wpide_cf7_ref_start  = 1000;

add_filter( 'wpcf7_special_mail_tags', function ( $output, $name, $html = false ) use ( $wpide_cf7_ref_prefix, $wpide_cf7_ref_start ) {
    if ( '_wpide_ref' !== $name ) {
        return $output;
    }

    static $ref = null;

    if ( null === $ref ) {
        $next = max( (int) get_option( 'wpide_cf7_ref', $wpide_cf7_ref_start ), $wpide_cf7_ref_start ) + 1;
        update_option( 'wpide_cf7_ref', $next, false );
        $ref = $wpide_cf7_ref_prefix . $next;
    }

    return $ref;
}, 10, 3 );
```

## Notes

Change the prefix and starting number at the top; the counter is shared by all forms and stored in an option.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Sequential Reference Number Mail Tag 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/
