使用 UTF-8 编码网页中的瑞典语字符创建 Outlook 邮件
我有一个数据库驱动的网站,用 php 编写,需要从数据创建电子邮件。所有数据和每个页面均以 UTF-8 编码,并包含大量瑞典语字符 åäö。我的 mailto-link 中有以下内容:
<a href="mailto:[email protected]?body=Hej!%0D%0AåäöÅÄÖ">Mailto-link</a>
并且电子邮件正文应该显示为
Hej!
åäöÅÄÖ
这至少可以使用 Internet Explorer 8 和 Firefox(尚未在 Chrome 或 Safari 中测试)与 Outlook 2007 一起使用。但是,在 Internet Explorer 7 或更早版本中,åäö 显示为奇怪的字符。我们的许多客户都被 IE 6 和 7 困住了。对于如何实现这一点有什么建议吗?
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:[email protected]?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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您遇到这样的问题,只需将导致问题的内容放入此 Javascript 警报语句中,然后将其粘贴到 Opera 或 Firefox 等不错的浏览器的地址栏中。
例如,如果执行,
您将得到
%E5%E4%F6%C5%C4%D6
。您可以复制警报语句显示的文本,然后在 mailto 链接中使用它:mailto: [电子邮件受保护]?body=嘿!%0a%E5%E4%F6%C5%C4%D6
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.
For example, if you execute
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:[email protected]?body=Hey!%0a%E5%E4%F6%C5%C4%D6
我认为,如果您尝试使用“mailto:”链接来解决问题,那么浪费的可能的浏览器/电子邮件客户端组合会给您带来无尽的悲伤。理论上 url 编码应该可以工作,但是当我过去尝试过这个时,我发现从 PHP 发送电子邮件更容易。
但这带来了其他挑战,例如确保垃圾邮件发送者无法将您的服务器用作电子邮件网关(例如,在表单中使用联系人 ID 号码而不是电子邮件地址)。验证码和速率限制可能也是一个好主意。
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.
URL 编码 字符(不仅仅是换行符)可能 帮助。在 PHP 中,正确的函数是
urlencode()
。URL encoding the characters as well (not just the line breaks) might help. In PHP, the right function would be
urlencode()
.