1

I would like to create an HTML email using JavaScript so that the draft is ready, and the user can send the email.

Here is what I have tried so far:

location.href = "mailto:"+"isflibrary.net.com.de.xxx"+'?cc='+"emailCC"+'&subject='+("Stuff bought by: ", email)+'&body='+"<a href="https://www.mywebsite.com">Visit mywebsite.com!</a>";

Wrong output: wrong output

Output that I want: enter image description here

2
  • In case the OP provides the example as executable snippet one (the OP too) immediately could see whether and/or where the approach does fail. Commented Sep 5, 2021 at 8:59
  • even if email was declared ... + ("Stuff bought by: " , email ) + ... obviously features a wrong syntax. Within the concatenation there can not be all of a sudden two comma separated values Commented Sep 5, 2021 at 9:11

1 Answer 1

1

Is this what you were trying to do?

$(document).ready(function() {
  $('#btn').click(function() {
    mailto = 'isflibrary.net.com.de.xxx';
    emailCC = '[email protected]';
    subject = 'Stuff bought by: ' + mailto;
    htmlBody = '<a href="https://www.mywebsite.com">Visit mywebsite.com!</a>';
    location.href = "mailto:" + mailto + "?cc=" + emailCC + "&subject=" + subject + "&body=" + htmlBody;
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button id=btn>e-mail</button>

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

2 Comments

Thanks for your reply, but the body still appears as HTML code.
Ok, I thought it was a syntax problem, so I have bad news. It can't be done: SO Answer

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.