问题
I'm trying to create a mailto link that contains french accented characters as the subject and email body. Both HTML and URI encoding the chars does not work. Here is my code:
<a href="mailto:%20?subject=ce%20titre%20est%20cass%C3%A9.&body=travaux%20deja!%20cesser%20d'%C3%AAtre%20t%C3%AAtu">SEND EMAIL</a>
Same result occurs without URI encoding:
<a href="mailto:?subject=ce titre est cassé&body=travaux deja! cesser d'être têtu">SEND EMAIL</a>
No Matter how i do it, the new email opens up with the broken characters. URI encoded Spaces and line-breaks work fine, but anything that is not ANSI is broken. I should note that I am testing in both english and french versions of MS Outlook 2007. Anyone know how to get this to work?
回答1:
In IE 8 its an setting option. Tools -> Options -> Advanced. Under International check the option "Use UTF-8 for mailto links".
Under Windows XP this setting is disabled by default. Under Windows 7 its enabled by default.
Hope this helps
回答2:
Everything in mail header (including subject) must be MIME-encoded according to this RFC,
http://www.ietf.org/rfc/rfc2047.txt
It's not trivial to do this but you can find code to handle it in most languages.
The properly encoded text looks like this,
=?ISO-8859-1?B?SWYgeW91IGNhbiByZWFkIHRoaXMgeW8=?=
EDIT: Try this to see if it's what you want,
<a href="mailto:your@email.com?subject=%3d%3fISO-8859-1%3fB%3fY2UgdGl0cmUgZXN0IGNhc3Pp%3f%3d&Content-Type=text%2fplain%3b+charset%3dISO-8859-1&body=travaux%20deja!%20cesser%20d'%C3%AAtre%20t%C3%AAtu">SEND EMAIL</a>
Replace email with your address.
回答3:
Got it! This may or may not be a bug in Microsoft Outlook/Entourage. I changed my default mail reader to Mail.app and it works beautifully with urlencoding. The (maybe) bug only appears to affect one of the 2 accented e characters in your example. Perhaps Outlook/Entourage is not handling miltibyte UTF8 chars correctly?
回答4:
For example, with mootools (but could be another framework or even 'raw' javascript), I usually do this, and it works mac/pc with the main browsers/clients:
window.addEvent('domready', function(){
//get the links to encode
var links_to_encode = $$('#page ul li a');
links_to_encode.each(function(link){
//check if the link has an href
var original_href = link.get('href');
if(original_href){
//substitute it with the encoded version
link.set('href',encodeURI(original_href));
}
});
});//fine domready
Bye!
来源:https://stackoverflow.com/questions/1472506/broken-accented-characters-in-a-mailto-link