2

I have a server-side code which creates html markup and sends it as an email. In the content of this email, I have added some date times. Something similar to:

Thu, 30 May 2019 08:13:24 GMT

What I want to do is to convert this date time to a local one once it was opened. I have tried the following approach:

<html>
    <body>
        <h1 style="color: #5e9ca0;">Hello, John Doe!</h1>
        <p style="color: #2e6c80;">We kindly ask you to return it no later than: <u><span id="returnDeadline">Fri, 21 Jun 2019 09:27:37 GMT</span></u></p>
    </body>
</html>
<script>
  (function() {
    let returnDeadlineContainer = document.getElementById('returnDeadline');
    returnDeadlineContainer.innerText = (new Date(returnDeadlineContainer.innerText)).toLocaleString();
  })();
</script>

If I save this and run it on my local machine it works as expected in the browser, but once I send it to the email it fails and the JS doesn't get invoked. I think there's a lot explained about this issue here: HTML email with Javascript

So, I was wondering how could I achieve this in the simplest possible way. I was looking for HTML tags (like <time>) but they don't seem to do the trick.

Syfer
  • 4,262
  • 3
  • 20
  • 37
user2128702
  • 2,059
  • 2
  • 29
  • 74
  • Email clients don't run javascript, so you can't do this – Liam Jun 21 '19 at 09:55
  • Possible duplicate of [Add javascript in the email](https://stackoverflow.com/questions/5193860/add-javascript-in-the-email) – Liam Jun 21 '19 at 09:56
  • 1
    *(do) this in the simplest possible way* you need to format the time **before you send it**, so you need to know what time zone each person is in (somehow). Then tailor each email before you send it with whatever technology your using to create the emails. – Liam Jun 21 '19 at 09:58

0 Answers0