-1

My Website is a shopping website(Currently in Dev)...

Im using a CMS which sends emails to customers after they have made a purchase giving details about their order.

Can i use javascript within the email template to check for a condition.Basically this email will be going out to 'N' number of users and i have a 'X' number of user who should get a slightly modified email based on a condition.

HERE IS THE TEMPLATE.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>Untitled Page</title>
    </head>
    <body>
        BLAH BLAH BLAH
        <span style="font-family: arial;">Thank you. Your order is confirmed. Please print a copy for your records.</span>        
       BLAH BLAH BLAH
    </body>
</html>

I understand that most email clients do not support Javascript, So is there any way within the email itself that i can change the contents of the mail based on conditions i choose.

MarsOne
  • 2,155
  • 5
  • 29
  • 53
  • possible duplicate of [Is JavaScript supported in an email message?](http://stackoverflow.com/questions/3054315/is-javascript-supported-in-an-email-message) – morten.c Apr 03 '14 at 11:47
  • Well, this does look like a duplicate. But all i wanna know is can i generate different emails to differentcustomer based on conditions instread of using multiple templates – MarsOne Apr 03 '14 at 11:49
  • If you're able to execute the javascript on the server side - before the email is send - then it would be possible. But if the condition is going to be executed on the e-mail client it's not possible (at least not in all E-Mail clients). – morten.c Apr 03 '14 at 11:51
  • I don't know what kind of CMS you're using, but often it's possible to use a server-side templating language (e.g. Smarty for the most PHP CMS) inside your E-Mail templates. – morten.c Apr 03 '14 at 11:52
  • 2
    As others have said, this is a server-side issue. If your server is sending emails (which it must, because it's not possible from the client) then the server **should** have the ability to process the content of the email being sent. This is where your logic should reside – freefaller Apr 03 '14 at 11:56

3 Answers3

1

I got this to work... The solution was to have the condition server side using a xsl template

<xsl:if test="expression">
  ...some output if the expression is true...
</xsl:if>
MarsOne
  • 2,155
  • 5
  • 29
  • 53
1

As suggested, you need to make your changes first as the email has to go out statically (as is).

This is often referred to as "dynamic content" in the email marketing world, and is the most effective way to send different versions of the email. Most ESP's have dynamic content or the more simple "merge tags" to do this.

This is a technique used for mass emailing one email to many (usually marketing/promos etc), while you are intending on sending an email based on individual user actions. I'd suggest you look into a "transactional email", a service like Mandrill, Sendgrid or Mailjet would be ideal to power this for you. Each has a solid API and is cost effective.

There is only one way to switch content after sending an email - updating an image. If you are linking to an image hosted on your server, you can update it there and it will display in its current state is when the email is opened.

John
  • 11,985
  • 3
  • 45
  • 60
0

Can i do this in the email?

No, and you should do that stuff server-side, that's pretty much the standard.

freefaller
  • 19,368
  • 7
  • 57
  • 87
Nabil Kadimi
  • 10,078
  • 2
  • 51
  • 58