16

我需要在正文中发送我网站的 URL,以便邮件收件人可以单击该 URL 加入我的网站。

然而,目前邮件客户端呈现这样的邮件:

链接在这里http://www.example.com/foo.php?this=a

符号上的 URL 被截断&,因此整个加入过程失败。如何在 mailto 正文中传递http://www.example.com/foo.php?this=a&join=abc&user454之类的 URL?

我当前的 HTML 如下:

<a href="mailto:test@test.test?body=Link goes here http://www.example.com/foo.php?this=a&amp;really=long&amp;url=with&amp;lots=and&amp;lots=and&amp;lots=of&prameters=on_it
">Link text goes here</a>
4

4 回答 4

27

您需要对 URL 进行编码。这个URL 解码器/编码器工具可以解决问题。以下似乎有效

<a href="mailto:test@test.test?body=Link goes here http%3A%2F%2Fwww.example.com%2Ffoo.php%3Fthis%3Da%26join%3Dabc%26user454
">Link text goes here</a>
于 2011-01-17T05:59:39.800 回答
11

我将对您正在使用的链接进行 URL 编码,因此它将是:

<a href="mailto:test@test.test?body=Link%20goes%20here%20http%3A%2F%2Fwww.example.com%2Ffoo.php%3Fthis%3Da%26join%3Dabc%26user454">Link text goes here</a>
于 2011-01-17T05:56:56.830 回答
5

您可以输入 javascript:alert(escape("YOUR URL")); 在浏览器的地址框中,获取对 mailto 链接安全的 URL。例如,在浏览器的地址框中键入以下内容,然后按 Enter。

javascript:alert(escape("http://www.example.com/foo.php?this=a"));

您将看到一个消息框。

http%3A//www.example.com/foo.php%3Fthis%3Da

基于 Opera 和 Mozilla 的浏览器允许您从警报框中复制显示的内容。

您可以通过键入来改进它

javascript:alert("mailto:MyEmailAddress@Example.com?subject=My Subject&body="+escape("http://www.example.com/foo.php?this=a"));

以便您获得链接中包含的主题和正文。其他改进可能是使用 From 名称和使用 %0a 的换行符。

javascript:alert("mailto:Just Me <CMyEmailAddress@Example.com>?subject=我的主题&body=这是链接:%250a"+escape("http://www.example.com/foo.php?this=一种”));
于 2011-01-17T06:26:10.407 回答
2

正如我看到你正在使用 php 那么你可以使用“urlencode()”函数

<a href="mailto:test@test.test?body=Link goes here <?php echo urlencode('http://www.example.com/foo.php?this=a&amp;really=long&amp;url=with&amp;lots=and&amp;lots=and&amp;lots=of&prameters=on_it
');?>">Link text goes here</a>
于 2013-01-08T16:42:51.593 回答