If you’re using a plugin to capture form submissions, you might already have access to one.
With Flamingo version 1.5+, you can use [_serial_number] in your mail templates, “This tag is replaced by a numeric string whose value increments, so this tag can work as the serial number of each submission”
Otherwise, you’ll need to track the number of form submissions yourself. First, you’ll need to increment the count and save it upon each form submission, then replace a custom placeholder mailtag with that value in the email.
We could do it like this:
In your mail template(s), add an arbitrary placeholder like this:
Serial: [serial_number]
You don’t actually need to create a custom form tag for this, and in fact, you probably shouldn’t since the value gets calculated only after a submission was successful. You don’t want to count the ones that end up in spam, right?
Then in a code snippet, we could do it like this:
/**
* Custom Email Behavior on Contact Form 7 Form Submission
*
* @param WPCF7_ContactForm $contact_form The current contact form.
* @param bool $abort If the submission is being aborted.
* @param WPCF7_Submission $submission The current submission data.
*
* @return void
*/
function au_save_serial($contact_form, &$abort, $submission)
{
// Get the form's current count
$count = (int)get_post_meta($contact_form->id(), '_submission_count', true);
// Increment it
$count++;
// Save it back to the form
update_post_meta($contact_form->id(), '_submission_count', $count);
// Format it
$serial = sprintf('support-%s-%03d', date('Y'), $count); // E.g. "support-2026-001", "support-2026-002", etc.
// Replace the placeholder in the email with the formatted value
$mail = $contact_form->prop('mail'); // Get the first mail property
$mail['body'] = str_replace('[serial_number]', $serial, $mail['body']);
// Don't forget the second email!
$mail2 = $contact_form->prop('mail_2'); // Get the second mail property
if ($mail2['active']) {
$mail2['body'] = str_replace('[serial_number]', $serial, $mail2['body']);
}
// Set the mail properties with the updated values
$contact_form->set_properties(array(
'mail' => $mail,
'mail_2' => $mail2
));
}
add_action('wpcf7_before_send_mail', 'au_save_serial', 10, 3);
Now this could certainly work, but there are a few drawbacks to this. For one, if more than one submission was submitted simultaneously, you could get duplicate serial numbers (it’s often why I go for the GUID approach!). Secondly, if you’re storing submissions anywhere, the serial number here is not saved alongside the submission.
If either of those things are dealbreakers, let me know and I can give you a more robust snippet to use.