Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prepopulating an email message using javascript

I have an application which displays a list of users , When clicking on the email button I want the email client to open up with a prepopulated message ( I make the message using javascript) , I am not sure about how to prepopulate the message

Any help would be appreciated

I would post snippets , but honestly I dnt know how to start with this

like image 959
alex Avatar asked Mar 05 '26 06:03

alex


2 Answers

URI encode the text and then append it to a mailto: URL:

<a href='mailto:[email protected]?body=text%20here'>Send mail!</a>

More generally, you can use:

  • subject
  • body (multiple body parameters will put each on a new line)
  • CC
  • BCC

with an ampersand (&) between each pair.

mailto:[email protected]?subject=Hi&body=some%20text
like image 162
Dennis Avatar answered Mar 06 '26 19:03

Dennis


You can use jQuery to find all the links that have mailto:, then process their href to add the message body:

$("a[href^='mailto:']").prop( "href", function(i, prop){
     return prop + "?body=" + encodeURIComponent( "Your message here" );
});

Demo:

http://jsfiddle.net/6qXrU/

like image 27
Esailija Avatar answered Mar 06 '26 20:03

Esailija