当我使用mailto:时,是否可以设置电子邮件的主题/内容?
当前回答
我把它分成几行,让它更容易读。
<a href="
mailto:johndoe@gmail.com
?subject=My+great+email+to+you
&body=This+is+an+awesome+email
&cc=janedoe@gmail.com
&bcc=billybob@yahoo.com
">Click here to send email!</a>
其他回答
是的,你可以这样做:
mailto: email@host.com?subject=something
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>
您可以使用此代码设置主题,正文,抄送,密件
mailto: URL方案在RFC 2368中定义。此外,在RFC 1738和RFC 3986中定义了将信息编码为url和uri的约定。它们规定了如何将正文和主题标题包含到URL (URI)中:
mailto:infobot@example.com?subject=current-issue&body=send%20current-issue
具体来说,您必须对电子邮件地址、主题和正文进行百分比编码,并将它们放入上述格式。百分比编码的文本在HTML中使用是合法的,但是根据HTML4标准,这个URL必须是在href属性中使用的实体编码:
<a href="mailto:infobot@example.com?subject=current-issue&body=send%20current-issue">Send email</a>
最常见的是,下面是一个简单的PHP脚本,它对上述内容进行编码。
<?php
$encodedTo = rawurlencode($message->to);
$encodedSubject = rawurlencode($message->subject);
$encodedBody = rawurlencode($message->body);
$uri = "mailto:$encodedTo?subject=$encodedSubject&body=$encodedBody";
$encodedUri = htmlspecialchars($uri);
echo "<a href=\"$encodedUri\">Send email</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>
推荐文章
- 使伸缩项目正确浮动
- 形式内联内的形式水平在twitter bootstrap?
- 自定义元素在HTML5中有效吗?
- 如何触发自动填充在谷歌Chrome?
- 创建圈div比使用图像更容易的方法?
- 为什么Chrome浏览器不正确地确定页面是在不同的语言,并提供翻译?
- 在网页上用鼠标模拟震颤(例如帕金森病)?
- Bootstrap抛出Uncaught错误:Bootstrap的JavaScript需要jQuery
- 如何改变文本区域的边框颜色:焦点
- 我如何设置背景颜色为文本的宽度,而不是整个元素的宽度,使用CSS?
- 如何删除和清除所有的本地存储数据
- 强制打开“另存为…”弹出打开文本链接点击PDF在HTML
- 如何修改标签文本?
- 在HTML中还有其他有用的空格码吗,比如半空格的 , em-spaces, en-spaces等等?
- 输入触发器按钮单击