Getting around mailto / href / url character limit

萝らか妹 提交于 2019-11-29 06:28:33

Is there a way to get around the limit?

Very hardly.

It is even probable that the limitations vary from browser to browser, or from E-Mail client to E-Mail client.

I would rather use a HTML form and a server-side script to send the message.

Yes, there is a limit on the length of the URL.

The limit varies from browser to browser, so you should keep the URL below 2000 characters to be safe.

Internet Explorer seems to be the browser that is having the shortest limit. According to this article it's 2083 characters.

Yes there are issues with Mailto tag it varies from browser to browser and email client to email client . In case of this issues try server side script to overcome this issue . Mailto at times behaves very abnormal

I know this question is old, but I had a similar problem, hitting the limit as I needed to send the email into many recipients.

I came across this solution, but I don't understand why it works, I leave it here anyway

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);
  }
}

usage:

var emails = 'a@a.com;b@b.com;c@c.com';
sendEmails(emails);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!