Search code examples
htmlemailrandomtimestampmailto

Is there a way to use a mailto: link that includes a timestamp or some sort of unique code?


I'd like to have a link like so:

mailto:foo@bar.com?subject=email&body=TIMESTAMP

or

MATMSG:TO:example@example.com;SUB:email;Body:TIMESTAMP;;

But in the subject line or in the body, I'd like it to include any of these options:

  1. A timestamp
  2. Sort of message like 'Message number #' which counts the number of times it's been used
  3. Any sort of unique random code of gibberish

I was hoping it would be possible to somehow import the contents from another website like this or something. Is there any way to do this using a stand alone link? Ultimately, I'm hoping this link can used with a QR code.

Thanks in advance.


Solution

  • At a glance I think there are 2 ways to do that:

    • generate the link with javascript:

      document.write('<a href="mailto:foo@bar.com?subject=email_' + new (Date().getTime()) + '"></a>');
      
    • or generate the link with server side scripting, for example PHP:

      <?php
          echo "<a href="mailto:foo@bar.com?subject=email_".round(microtime(true))."</a>"
       ?>
      

    Personally I would use javascript, I think it's more appropriate for this kind of stuff.

    Edit:

    Even better is using a javascript bookmarklet, that way it can be used as a link:

    javascript:location.href='mailto:example@example.com?SUBJECT=Data&BODY=Code:'+new Date().getTime()