Within the below code for Microsoft Email, I am tring to figure out how to place the current day and date in the "Subject=" field.

<html>

<body>

<p>
This is today's quote:
<a
href="mailto:?cc=&bcc=&
subject=CURRENTDAYDATE&body=Today's%20Market%20Information">Markets!</a>
</p>

</body>

</html>

Dani AI

Generated

Short answer and direction: as and pointed out, plain HTML cannot insert a changing value like "today" into a mailto subject at load time. was on the right track with JavaScript, but avoid document.write and build the link via the DOM so it works reliably across browsers. If the message must be sent automatically or headers must be controlled, use a server-side mail handler instead.

A safe, practical client-side pattern — put a simple anchor in the page and have JavaScript set its href on load. The example below shows a small formatter, uses encodeURIComponent for safety, and updates the link without document.write:

<a id="sendReport" href="mailto:">Send report</a>

<script>
(function(){
  var link = document.getElementById('sendReport');
  if (!link) return;
  function pad(n){ return n < 10 ? '0' + n : n; }
  var d = new Date();
  var yyyy = d.getFullYear();
  var mm = pad(d.getMonth() + 1);
  var dd = pad(d.getDate());
  var subject = 'Report - ' + yyyy + '-' + mm + '-' + dd;
  var recipients = 'recipient@example.com';
  var cc = 'cc@example.com';
  var body = 'Summary attached.';
  var href = 'mailto:' + recipients +
             '?subject=' + encodeURIComponent(subject) +
             '&cc=' + encodeURIComponent(cc) +
             '&body=' + encodeURIComponent(body);
  link.setAttribute('href', href);
})();
</script>

Caveats and troubleshooting: mailto behaviour depends on the user's mail handler and webmail (some webmail clients handle mailto differently). The prefilled subject is editable by the user; the SMTP Date header is added by the mail server and cannot be set reliably from a mailto link. Use server-side sending (PHP/Node/etc.) if you need automation, header control, or to hide recipients from page source. If JavaScript may be disabled, provide a non-JS fallback (a simple contact form that posts to your server).

Recommended Answers

All 5 Replies

I don't think this can be done with just html like you are trying to do.

Why do you need to do this when the date is automatically set on emails by the server?

I was thinking that too, but if your determined, you could write your mail as javascript (which might help as antispam aswell) then you could possibly do it. something like this

<Script Language="JavaScript">
<!--
// The following is the same basic example as above,
// however we add a variable for the subject and the document
// title as the subject in the mail link.
var u_a="mail"
var u_b="to:"
var u_c="any_address"
var u_d="@"
var u_e="server"
var u_f="name"
var u_g=".com"
var u_h="subject=something
"
document.write ("<a href='"+ u_a + u_b + u_c + u_d + u_e + u_f + u_g + u_h + document.title +"'>Mail Link with Subject</a>");
-->
</script>

then maybe you could work in some javascript to put date in subject, this is the get date (only way I know)

<script type="text/javascript">

document.write(Date())

</script>

I have no clue hopw though, just trying to help in some small way. Matt Evans is the bloke you need! :D

Thanks for your help.

Reggiezack

Thanks much.

Reggiezack

thanks for this information.. html alone won't do this..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.