• parkerboe

    (@parkerboe)


    It would be awesome if there was a custom shortcode you can use within the emails received that assigns a unique ID to each email received. That way, each request can be tracked easier in chats with coworkers.

    If it’s too hard to implement sequential numbers (i.e. 1, 2, 3, 4), then random hex IDs may be viable, like Git commits (e.g. aaa7ef8f).

    Thanks for your consideration!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Takayuki Miyoshi

    (@takayukister)

    Each email message has a unique value in its Message-ID header.

    Thread Starter parkerboe

    (@parkerboe)

    Is there a way I can put that in the email body or the email subject line?

    zzusyu

    (@zzusyu)

    Hey,

    here is a solution that should be enough for your problem:

    add_filter('wpcf7_special_mail_tags', function($var, string $mail_tag_name, string $html, WPCF7_MailTag $mail_tag) {
      if ( $mail_tag_name === '_mail_unique_id' ) {
        $form = WPCF7_ContactForm::get_current();
        $submission = WPCF7_Submission::get_instance();
    
        $offset = 0;
        $length = 40;
        $hash_string = (string) $form->id() . (string) $form->shortcode() . (string) $submission->get_posted_data_hash();
        $var = sha1($hash_string, false);
        $var = substr($var, $offset, $length);
      }
      return $var;
    }, 10, 4);

    Copy that into one of your own plugins or to the functions.php in your theme. If the output string is to long you can change the variable $length to your desired length.

    You can then use _mail_unique_id in your mail.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Feature Request: Add a random ID or numbering to contact for reference’ is closed to new replies.