Thursday, December 24, 2015

JavaScript - Simple Email without any server code

I have thought of using simple JavaScript Email feature using "mailTo:". But this is not used for bigger body contents or if you planned for much styles.

Use below JavaScript Method to send emails.

You can use more URL encode to format body.

Ref for URL Encode:  http://www.w3schools.com/tags/ref_urlencode.asp
For MailTo Documentation:  http://www.ietf.org/rfc/rfc2368.txt

JavaScript:

function SendEmail() {

   var subject = 'Mail subject goes here..';
   var body = 'Hi,%0D%0A %0D%0A' +
            'Some of your content %0D%0A%0D%0A' +
            'Next line of body goes here.%0D%0A' +
            '%E2%80%A2 Text within Bullet Text here %E2%80%A2 %0D%0A' +
           
            '%0D%0A Thanks & Regards,%0D%0A' +
            'Your signature goes here..';


    window.location = 'mailto:?subject=' + subject + '&body=' + body;

    return false;

};

HTML:

<input type="button" value="Email" onclick="SendEmail();"/>

No comments:

Post a Comment