According to Sending emails with Javascript, one way to do it is the following:
function sendMail() {
var link = "mailto:me@example.com"
+ "?cc=myCCaddress@example.com"
+ "&subject=" + encodeURIComponent("This is my subject")
+ "&body=" + encodeURIComponent(document.getElementById('myText').value)
;
window.location.href = link;
}
However I'm trying to personalize it, sending emails with variables. I did this:
function sendMail(subject="test", body, mail="test@gmail.com") {
var link = `mailto:${mail}`
+ "&subject=" + encodeURIComponent(`${subject}`)
+ "&body=" + encodeURIComponent(`${body}`)
;
window.location.href = link;
But, when sending the email, I achieve this fail:
It seems like it is not recognizing each variable. How to solve it?