jquery – How to send mails with Javascript "mailto"?


I wanted to know how to send mails with and that inside the mail I have a subject and a body to be able to write.

My question is how to add inputs to the function, I know it would be something like this:


To the Jquery function that is the following

    $(location).attr('href', 'mailto:?subject='
                         + encodeURIComponent("This is my subject")
                         + "&body=" 
                         + encodeURIComponent("This is my body")


It is not possible to send an email only with Javascript, you need a "server-side" language that receives the information (for example PHP) to be able to send it.

You can only open the user's mail client, which is what you do with the current code.

As for adding the input values ​​to the href, simply change the texts to the jQuery function you name:

$(location).attr('href', 'mailto:?subject='
                         + encodeURIComponent($('#input1').val())
                         + "&body=" 
                         + encodeURIComponent($('#input2').val())
Scroll to Top