1

I have to sent a confirmation email to the users. and on clicking of a link, i want to open their default email client and add a HTML into the body tag.

var subject = Your transaction No: +': ' + $('#confirmationNumber').text()+ ' is confirmed';
var emailBody = $('#confirmation').html();
$(this).attr('href','mailto:'+userEmail+'&subject=' + subject +'&body='+ emailBody); 

it want the HTML in 'emailBody' to get appended to the body as HTML. But it displays me the entire HTML tags instead.

Is there a way i can append a HTML in the body ?

3 Answers 3

2

The answer is short but unfortunate:

No.

When using mailto:-links, you can only specify text, not HTML. Even if the user’s mail client composes a mail message using HTML, your body text will only be inserted as text.

There’s nothing you can do about that from a web page.

Sign up to request clarification or add additional context in comments.

Comments

0

Use

var emailBody = $('#confirmation').text();

2 Comments

yeh i used that... but it appends all the text in one line in the email body... I want some bold tags and line breaks in them.
Body must be 'text/plain', You cannot use HTML Tags in there.
0

First of all, some fixes to your code:

var subject = 'Your transaction No: ' + $('#confirmationNumber').text() + ' is confirmed',
    emailBody = $('#confirmation').html();
$(this).attr('href', 'mailto:' + userEmail + '&subject=' + subject + '&body=' + encodeURI(emailBody));
  • Use single var keyword and separate variables with commas
  • subject was concatenated badly

Next, if you want to pass html code in link you have to encode special chars, which encodeURI() does.


Oops, encoded body isn't treated as html in email client.. I googled for a while and it seems you can't pass it correctly, can't you send a message instead of opening client?

1 Comment

1stly sorry for the bad subject concatenaiton, i had typed that one. and :( for hte encodeURI. It was a client requirement. But ur right.. i will send it as a messge instead..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.