Description
This plugin gives every message sent through Contact Form 7 its own reference number, such as 0042, INQ-0042 or 20261121-0042.
Put the mail-tag [_reference_number] wherever the number should appear: in the subject or the body of the mail you receive, in the automatic reply to the visitor, and in the message the visitor sees after sending the form.
Numbers are not wasted
- A submission with an input error, or one judged to be spam, does not use up a number.
- If the mail cannot be sent, or another plugin stops the submission, the number is given to the next message instead.
- When several visitors send the form at the same moment, each message still gets a different number.
Every form counts on its own, in the format you choose
- A prefix, for example
INQ- - The number of digits, filled up with zeros (
0001) - A date inside the number: the year, the year and month, or the year, month and day
- Reset the count every year, every month, every day, or never
- The start number
- Dates and resets follow the time zone of your site (Settings > General), whether it is set as a city or as a UTC offset.
It fits into Contact Form 7
- The settings are a tab in the Contact Form 7 form editor. No menu item and no separate settings screen are added.
- If Flamingo is active, the number is kept with the stored message. You can search for it in Flamingo, and it is included in Flamingo’s CSV export. Flamingo is optional.
- Other plugins and themes can read the number through a function, an action and a filter (see “For developers” below).
- No outside service is contacted, and nothing is added to the pages your visitors see: no script, no stylesheet.
Contact Form 7 5.9 or later is required.
This plugin is not affiliated with or endorsed by the authors of Contact Form 7 or Flamingo.
How to use
- Edit a form under Contact > Contact Forms.
- On the Mail tab, put
[_reference_number]where you want the number, for example in the subject:[_reference_number] Inquiry from [your-name]. It works the same way in Mail (2), the automatic reply. - To show the number to the visitor, open the Messages tab and add the tag to the text for a successfully sent message, for example:
Thank you for your message. Your reference number is [_reference_number]. - To change how the number looks, open the Reference Number tab. It also shows the number the next message will get.
Without any settings, numbers look like 0001, 0002, 0003.
For developers
tdkrn_get_number()returns the number of the message that is being submitted in the current request, or an empty string. It is available from thewpcf7_before_send_mailaction (priority 2 or later) until the end of the request. Until the mail has been sent the number is provisional: if sending fails, the function returns an empty string again and the number goes to the next message.- The action
tdkrn_number_assignedfires when the mail was sent and the number is final. Example:add_action( 'tdkrn_number_assigned', function ( $number, $contact_form, $sequence ) { /* ... */ }, 10, 3 ); - The filter
tdkrn_numberchanges how a number looks. Example:add_filter( 'tdkrn_number', function ( $number, $sequence, $form_id, $day ) { return $number . '-W'; }, 10, 4 );Keep the result unique. - The mail-tag is replaced through Contact Form 7’s own
wpcf7_special_mail_tagsfilter, so it also works in any text that another plugin passes throughwpcf7_mail_replace_tags()while a message is being sent.
Installation
- Install and activate Contact Form 7 (5.9 or later).
- Install and activate this plugin.
- Edit a form and put
[_reference_number]on the Mail tab, as described under “How to use”. - Send a test message from your own form and check the number in the mail.
FAQ
Where are the settings?
In the Contact Form 7 form editor, on the Reference Number tab. Every form has its own settings and its own count.
Do I have to switch it on for each form?
No. Every form counts its sent messages from the moment the plugin is active. The number only appears where you put the [_reference_number] mail-tag.
When exactly does a message get a number?
After it has passed Contact Form 7’s validation and spam checks, just before the mail is written. The number becomes final when Contact Form 7 reports that the mail was sent. If Contact Form 7 reports that sending failed, the number is taken back and given to the next message.
A form that is set not to send mail (the skip_mail: on setting, or demo mode) counts as well: Contact Form 7 reports such a message as sent, so it gets a number.
Can a number ever be skipped?
Not by input errors, spam, or failed mail. Two rare cases remain. If PHP crashes at the very moment a mail is being sent, nobody can tell whether the mail went out, so that number is not used again; a skipped number is safer than the same number on two messages. And a number taken back after a failed mail is not carried over into the next year, month or day when the count is reset in between.
Can a message end up without a number?
Only if the database cannot be read or written at that very moment. The message is then sent anyway and the tag is left empty, because losing a message would be worse than a missing number.
Are the numbers always in the order the messages arrived?
Almost always. When a mail fails while other messages are being sent at the same moment, the number that was taken back goes to the next message, which may be a little later than a message with a higher number.
I already have numbered messages. Can I continue from the last number?
Yes. On the Reference Number tab, enter the next number as the start number, tick “Restart from the start number when I save this form”, and save the form.
I sent test messages. How do I start again from 1?
Tick “Restart from the start number when I save this form” on the Reference Number tab and save the form.
The tab warns that the same number is used again. Why?
The count is reset more often than the date in the number changes, for example a reset every day with only the year in the number. The number 2026-0001 would then be issued every day. Put a more detailed date in the number, or reset less often.
Which time zone decides when a day, month or year begins?
The time zone of your site, set under Settings > General. Both kinds of setting work: a city such as “Tokyo” and a UTC offset such as “UTC+9”.
Does it work without Flamingo?
Yes. Flamingo is only needed if you want messages, and their numbers, to be stored in WordPress.
Where is the number in Flamingo?
In the stored message, under Meta as reference_number and under Fields as reference-number. A message whose mail could not be sent is stored without a number.
Can I use the tag in the form itself, for example in a hidden field?
No. The number does not exist until a message has passed validation, so it cannot be part of the form the visitor fills in.
What is removed when I delete the plugin?
The count of each form and the number format of each form. Numbers that are already in mails you received, or in messages stored by Flamingo, are not touched.
What happens with a Contact Form 7 older than 5.9?
The plugin stays idle and shows a notice on the Plugins screen. Your forms keep working as before, without numbers.
Changelog
0.1.0
- First release.