html - Javascript adding linebreak in mailto body -


i'm setting body of email using values form

  firstname = bob   lastname = dole     ebody = 'first name: ' + firstname + '\r\n' + 'last name: ' + lastname    window.location.href = 'mailto:myemail@mycompany.com?subject=test   email&body=' + ebody; 

if "alert(ebody);" linebreak between firstname & lastname, when opens outlook, entire ebody string appears without linebreak in email body.

i've tried \n also. there can give line break?

thanks in advance

rfc 2368 says mailto body content must url-encoded, using %-escaped form characters encoded in url. characters includes spaces , (as called out explicitly in section 5 of 2368) cr , lf.

you writing

ebody = 'first%20name:%20' + firstname + '%0d%0a' + 'last%20name:%20' + lastname; 

but it's easier , better have javascript escaping you, this:

ebody = 'first name: ' + firstname + '\r\n' + 'last name: ' + lastname; ebody = encodeuricomponent(ebody); 

not save having identify , hex values of characters need encoded in fixed text, encode goofy characters in firstname , lastname variables.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -