当我使用mailto:时,是否可以设置电子邮件的主题/内容?
当前回答
注意,根据RFC 2368,不能在消息体中使用HTML:
特殊名称“body”表示关联的hvalue是消息体。“body”名称应该包含消息的第一个文本/纯正文部分的内容。mailto URL主要用于生成短文本消息,这些消息实际上是自动处理的内容(例如邮件列表的“订阅”消息),而不是一般的MIME体。
来源:https://stackoverflow.com/a/13415988/1835519
其他回答
是的,看看所有的提示和技巧mailto: http://www.angelfire.com/dc/html-webmaster/mailto.htm
邮件主题示例:
<a href=“mailto:no-one@snai1mai1.com?主选=免费巧克力">example</a>
邮件内容:
<a href="mailto:no-one@snai1mai1.com?subject=看这个网站&body=嗨,我发现了这个网站,认为你可能会喜欢它http://www.geocities.com/wowhtml/">告诉一个朋友</a>
正如注释中提到的,主体和主体都必须正确转义。使用encodeURIComponent(subject),而不是针对特定情况手工编码。
正如Hoody在评论中提到的,你可以通过在字符串中添加以下编码序列来添加换行符:
%0D%0A // one line break
诀窍在这里 http://neworganizing.com/content/blog/tip-prepopulate-mailto-links-with-subject-body-text
<a href="mailto:tips@neworganizing.com?subject=Your+tip+on+mailto+links&body=Thanks+for+this+tip">tell a friend</a>
下面是一个可运行的代码片段,可以帮助您生成带有可选主题和正文的mailto:链接。
function generate() { var email = $('#email').val(); var subject = $('#subject').val(); var body = $('#body').val(); var mailto = 'mailto:' + email; var params = {}; if (subject) { params.subject = subject; } if (body) { params.body = body; } if (params) { mailto += '?' + $.param(params); } var $output = $('#output'); $output.val(mailto); $output.focus(); $output.select(); document.execCommand('copy'); } $(document).ready(function() { $('#generate').on('click', generate); }); <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="text" id="email" placeholder="email address" /><br/> <input type="text" id="subject" placeholder="Subject" /><br/> <textarea id="body" placeholder="Body"></textarea><br/> <button type="button" id="generate">Generate & copy to clipboard</button><br/> <textarea id="output">Output</textarea>
mailto:joe@company.com?subject=Your+subject
<a href="mailto:manish@simplygraphix.com?subject=Feedback for
webdevelopersnotes.com&body=The Tips and Tricks section is great
&cc=anotheremailaddress@anotherdomain.com
&bcc=onemore@anotherdomain.com">Send me an email</a>
您可以使用此代码设置主题,正文,抄送,密件
推荐文章
- 使伸缩项目正确浮动
- 形式内联内的形式水平在twitter bootstrap?
- 自定义元素在HTML5中有效吗?
- 如何触发自动填充在谷歌Chrome?
- 创建圈div比使用图像更容易的方法?
- 为什么Chrome浏览器不正确地确定页面是在不同的语言,并提供翻译?
- 在网页上用鼠标模拟震颤(例如帕金森病)?
- Bootstrap抛出Uncaught错误:Bootstrap的JavaScript需要jQuery
- 如何改变文本区域的边框颜色:焦点
- 我如何设置背景颜色为文本的宽度,而不是整个元素的宽度,使用CSS?
- 如何删除和清除所有的本地存储数据
- 强制打开“另存为…”弹出打开文本链接点击PDF在HTML
- 如何修改标签文本?
- 在HTML中还有其他有用的空格码吗,比如半空格的 , em-spaces, en-spaces等等?
- 输入触发器按钮单击