-->

Creating Outlook mail with Swedish characters from

2019-08-11 06:25发布

问题:

I've got a database-driven website, written in php, which needs to create e-mails from the data. All data and every page is encoded in UTF-8, and contains plenty of the Swedish characters åäö. I've got the following in my mailto-link:

<a href="mailto:name@domain.com?body=Hej!%0D%0AåäöÅÄÖ">Mailto-link</a>

and the e-mail body is supposed to come out as

Hej!
åäöÅÄÖ

This works using Internet Explorer 8 and Firefox at least (haven't tested in Chrome or Safari) with Outlook 2007. However, in Internet Explorer 7 or earlier the åäö comes out as weird characters. Many of our clients are stuck with IE 6 and 7. Any suggestions on how to make this work?

回答1:

I think the wast number of possible browser/email client combinations out there is going to give you an endless amount of grief if you try to solve it with a "mailto:" link. Theoretically url-encoding should work, but when I've dabbled with this in the past I figured out it was easier to just send email from PHP in stead.

That brings other challenges though, such as making sure you don't make it possible for spammers to use your server as an email gateway (eg. use contact ID numbers in stead of email addresses in the form). Captcha and rate limiting is probably a good idea as well.



回答2:

If you ever face a problem like this just put the content that is causing the trouble in this Javascript alert statement and paste it in address bar of a decent browser such as Opera or Firefox.

javascript:alert(escape("problem-string-here"));

For example, if you execute

javascript:alert(escape("åäöÅÄÖ"));

you will get %E5%E4%F6%C5%C4%D6. You can copy the text displayed by the alert statement and then use it in your mailto link:

mailto:name@domain.tld?body=Hey!%0a%E5%E4%F6%C5%C4%D6



回答3:

URL encoding the characters as well (not just the line breaks) might help. In PHP, the right function would be urlencode().