How can I include a multi-line message in a mailto: URL?

Jayesh Nazre

Well you have to pass the parameter "body" a value.

To embed your message completely in your HTML page, you'll need to use JavaScript's escape() method to convert the text with new lines to something that can be used in a mailto URL.

<html>
<head>
<script language=javascript>

function send() {
  var lstr_data = "FIRST LINE" + "
" +
    "SECOND LINE" + "
" + "THIRD LINE";
  window.location.href="mailto:jayesh_nazre@hotmail.com" +
    "?body=" + escape (lstr_data);
}
</script>
</head>
<body>

<a href="javascript:send();">Send Message</a>
</body>
</html>

Instead, you can get the message from a TextArea on the page...

<html>
<head>
<script language=javascript>
function send() {

  window.location.href="mailto:jayesh_nazre@hotmail.com" + 
    "?body=" + document.frm_test.ta_body.value;

}
</script>
</head>
<body>

<form id=frm_test name=frm_test>

Mail Contents:

<TEXTAREA NAME=ta_body ROWS="6" COLS="55"> HELLO1 HELLO2 </TEXTAREA> <input type=button value=SendMail onclick=send()> </form> </body> </html>
Note if you need to specify the subject then u need to pass the parameter "subject" like this

window.location.href="mailto:jayesh_nazre@hotmail.com" +
   "?subject=" + "TEST MAIL";
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact