17

我在锚标记中有一个 mailto 链接

<a href="mailto:?subject=Subject&body=Body">Email This</a>

问题是 Body 参数是一篇巨大的文章,而且 url 似乎有字符限制。

有没有办法绕过限制?

4

4 回答 4

14

有没有办法绕过限制?

很难。

甚至可能限制因浏览器而异,或因电子邮件客户端而异。

我宁愿使用 HTML 表单和服务器端脚本来发送消息。

于 2010-11-01T08:18:06.090 回答
7

是的,URL 的长度是有限制的。

限制因浏览器而异,因此您应该将 URL 保持在 2000 个字符以下以确保安全。

Internet Explorer 似乎是限制最短的浏览器。根据这篇文章,它是 2083 个字符。

于 2010-11-01T08:20:35.463 回答
0

是的,Mailto 标签存在问题,它因浏览器和电子邮件客户端而异。如果出现此问题,请尝试使用服务器端脚本来解决此问题。Mailto 有时表现得很不正常

于 2012-07-25T07:35:51.373 回答
-1

我知道这个问题很老,但是我遇到了类似的问题,因为我需要将电子邮件发送给许多收件人,因此达到了限制。

我遇到了这个解决方案,但我不明白它为什么有效,我还是把它留在这里

function sendEmails(emails) {
  var timeout = 2000;
  var mailtoPrefix = 'mailto:?bcc=';
  var maxUrlCharacters = 1900;
  var separator = ';';
  var currentIndex = 0;
  var nextIndex = 0;

  if (emails.length < maxUrlCharacters) {
    window.location = mailtoPrefix + emails;
    return;
  }

  do {
    currentIndex = nextIndex;
    nextIndex = emails.indexOf(separator, currentIndex + 1);
  } while (nextIndex != -1 && nextIndex < maxUrlCharacters)

  if (currentIndex == -1) {
    window.location = mailtoPrefix + emails;
  } else {
    window.location = mailtoPrefix + emails.slice(0, currentIndex);
    setTimeout(function () {
      sendEmails(emails.slice(currentIndex + 1));
    }, timeout);
  }
}

用法:

var emails = 'a@a.com;b@b.com;c@c.com';
sendEmails(emails);
于 2018-02-02T20:19:06.043 回答