【问题标题】:How to pass an URL in mailto's body如何在邮件正文中传递 URL
【发布时间】:2011-06-10 06:26:28
【问题描述】:

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

但是目前邮件客户端是这样渲染邮件的:

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

网址在&符号处被截断,因此整个加入过程失败。如何在邮件正文中传递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>

【问题讨论】:

    标签: html css url mailto


    【解决方案1】:

    我会对你正在使用的链接进行 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>
    

    【讨论】:

    • 我刚试过。有用!只是使用了他给出的第一个链接,而不是第二个。
    【解决方案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>
    

    【讨论】:

      【解决方案3】:

      您可以输入 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 ?subject=我的主题&body=这是链接:%250a"+escape("http://www.example.com/foo.php ?this=a"));

      【讨论】:

      • 感谢转义功能!这就是我一直在寻找的
      【解决方案4】:

      您需要对 URL 进行编码。这个URL Decoder/Encoder tool 可以解决问题。以下seems to work

      <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>
      

      【讨论】:

      • 它将解决与 url 相关的任何问题,因此我将其标记为正确答案。
      猜你喜欢
      • 2020-05-23
      • 1970-01-01
      • 2021-10-30
      • 1970-01-01
      • 1970-01-01
      • 2015-06-26
      • 1970-01-01
      • 2018-06-18
      • 1970-01-01
      相关资源
      最近更新 更多