使用正文对 mailto 链接进行编码
我正在尝试使用 PHP 创建一个 mailto 链接。基本上我的函数从数据库获取正文,然后创建这样的 html 标签:
<a href="mailto:?subject=sample&body=sometexthere">send</a>
好吧,问题是我的正文可能包含非标准字符,如重音符号等,所以我需要在输出之前对正文进行编码;但我不知道该怎么做,因为当我的邮件客户端打开(Windows Live Mail)时,它会显示错误的正文字符。
我该如何解决这个问题?在正文中使用 unicode 文本的正确编码是什么?
预先非常感谢,
I'm trying to create a mailto link using PHP. Basically my function gets the body text from database and then creates the html tag like this:
<a href="mailto:?subject=sample&body=sometexthere">send</a>
well, the problem is that my body text may contain non standard characters, like accents and so, so i need to encode the body text before output it; but i don't know how to do it because when my mail client opens (Windows Live Mail) it displays wrong characters for the body.
How can i solve this? what is the right encoding to use unicode text into the body?
many thanks in advance,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我相信您正在寻找 php 的
htmlentities()
函数。I beleive you're looking for php's
htmlentities()
function.您必须实施这些替换
http://www.ietf.org/rfc/rfc2368
You have to implement those replacements
http://www.ietf.org/rfc/rfc2368
请注意,如果
sometexthere
中存在非 Ascii 字符,则 Outlook 似乎存在问题。请参阅这篇文章:mailto 特殊字符
Be aware that there seems to be an issue with Outlook if there are non-Ascii characters in
sometexthere
.See this post: mailto special characters
我遇到了同样的问题;我的第一直觉是使用 urlencode() ,但这不起作用。
尝试使用:
一般来说这个功能在跨不同系统工作时比较可靠;一个主要原因是
urlencode
将空格转换为+
,大多数邮件客户端都会保持原样。例如:
这对我有用。
I encountered this same problem; my first intuition was to use
urlencode()
but that did not work.Try using:
In general this function is more reliable when working across different systems; a major reason is that
urlencode
converts spaces to+
which will be left as-is by most mail clients.So for example:
This worked for me.