当使用mailto时,是否可以设置邮件的主题/内容?
是的,请查看使用 mailto: 的所有提示和技巧:http://www.angelfire.com/dc/html-webmaster/mailto.htm
mailto主题示例:
<a href="mailto:no-one@snai1mai1.com?subject=free chocolate">example</a>
邮件内容中添加mailto链接:
<a href="mailto:no-one@snai1mai1.com?subject=look at this website&body=Hi,I found this website and thought you might like it http://www.geocities.com/wowhtml/">tell a friend</a>
正如评论中所提到的,subject
和body
都必须得到适当的转义。对于每个内容,请使用encodeURIComponent(subject)
进行处理,而不是为特定情况手工编写代码。
如Hoody在评论中提到的,您可以通过在字符串中添加以下编码序列来添加换行符:
%0D%0A // one line break
<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中有定义。同时,将信息编码到URL和URI中的约定在RFC 1738和RFC 3986中有定义。这些规定了如何将body
和subject
头部包含进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命令中。
在mailto标记中添加?subject=来添加主题。
<a href="mailto:test@example.com?subject=testing out mailto">First Example</a>
我们也可以通过在标签末尾添加 &body 来在消息正文中添加文本,如下例所示。 <a href="mailto:test@example.com?subject=testing out mailto&body=Just testing">Second Example</a>
除了正文外,用户还可以输入 &cc 或 &bcc 来填写抄送和密送字段。
<a href="mailto:test@example.com?subject=testing out mailto&body=Just testing&cc=test1@example.com&bcc=test1@example.com">Third
Example</a>
mailto:joe@company.com?subject=Your+subject
我将其分成单独的行,以使其更易读。
<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表单元素和链接编码。
您可以在表单中输入主题、正文等内容,点击按钮,查看可粘贴到您页面中的mailto html链接。
您甚至可以指定很少被人知道和使用的元素:抄送(cc)、密送(bcc)、发件人邮箱。
[Test Zõne]
变成 %5BTest%20Z%C3%B5ne%5D
,这可能会避免一些垃圾邮件机器人)。 - Armfoot&#x
(避免一些垃圾邮件机器人)。 - Armfoot这里有个技巧: 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: email@host.com?subject=something