Question

I have a HTMl email template that I want to use for sending automated emails to people via Heroku. I am using Sendgrid add on for Heroku.

 var html_content = "Thank you for registering to visit Philippine Property Show 2014 organised by"+
 "PropertyGuru.This is the confirmation letter to your registration.Kindly present this letter at the registration counter for your entry to the event."
 +"<br> <br>Thank you once again and see you at the event.<br><br>
<strong>Philippine Property Show</strong><br>
<strong>29 - 30 November 2013</strong><br>
<strong>Orchard Hotel, Level 2, Conference Centre<br>
</strong><br>"+"
<strong><span >With Warm Regards,</span></strong><span ><br>
<br>
</span><strong><span >PropertyGuru Events</span></strong><span ><br>
<br> ";

I have the below function where I am trying to use the above variable.

    function send_mail_sendgrid(email_id){
sendgrid.send({
        to: email_id,
        from: 'events@PropertyGuru.com.sg',
        fromname: 'PropertyGuru Events',
        subject: 'Thank you for registering to visit Philippine Property Show 2014',
        html: html_content;
    }, function(err, json) {
        if (err) { return console.error(err); }
        console.log(json);
    });


 }

But everytime I run this , I get error -

 +"<br> <br>Thank you once again and see you at the event.<br><br>
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Unexpected token ILLEGAL
    at Module._compile (module.js:439:25)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/Users/bhagabanbehera/extra/pguru/app.js:7:14)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)

Obviously its not recognising my dumping in HTML code into a js variable. How do I go about doing this - sending an email via sendgrid with a template ?

Was it helpful?

Solution

The error is returned because you cannot break your string html_content with returns. Change your variable to the following:

var html_content = "Thank you for registering to visit Philippine Property Show 2014 organised by "
 +"PropertyGuru. This is the confirmation letter to your registration. Kindly present this letter at the registration counter for your entry to the event."
 +"<br><br>Thank you once again and see you at the event.<br><br>"
 +"<strong>Philippine Property Show</strong><br><strong>29 - 30 November 2013</strong>"
 +"<br><strong>Orchard Hotel, Level 2, Conference Centre<br></strong><br>"
 +"<strong><span>With Warm Regards,</span></strong><span><br><br></span>"
 +"<strong><span>PropertyGuru Events</span></strong><span><br><br>";

Also, remove the semi-colon inside sendgrid.send after html: html_content and it should work.

OTHER TIPS

I might chalk this up to a parser error, in delivering the error message, but you have a semi-colon after html_content. Try getting rid of that and re-running the code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top