使用mailto:时是否可以设置电子邮件的主题/内容?
我可以使用mailto:设置电子邮件的主题/内容吗?
Yes, you can like this:
mailto: email@host.com?subject=something
Yes:
Use this to experiment with mailto form elements and link encoding.
You can enter subject, body (i.e. content), etc. into the form, hit the button and see the mailto html link that you can paste into your page.
You can even specify elements that are rarely known and used: cc, bcc, from emails.
here is the trick 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>
我将其分成几行以使其更具可读性。
<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:joe@company.com?subject=Your+subject
您可以使用以下任一种方式将添加的主题添加到mailto命令。将?subject out mailto添加到mailto标签。
<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来填写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:
URL方案定义在RFC 2368。另外,在RFC 1738和RFC 3986中定义了将信息编码为URL和URI的约定。这些规定了如何将body
和subject
标头包含在URL(URI)中:
mailto:infobot@example.com?subject=current-issue&body=send%20current-issue
具体来说,您必须对电子邮件地址,主题和正文进行百分比编码,然后将其放入上述格式。百分比编码的文本在HTML中使用是合法的,但是href
根据HTML4标准,此URL必须是实体编码后才能在属性中使用:
<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>";
?>
<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查看所有提示和技巧: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)
在每种情况下使用,而不是为特定情况手工编码。
As Hoody mentioned in the comments, you can add line breaks by adding the following encoded sequence in the string:
%0D%0A // one line break
Note that it is not possible to use HTML in the message body, according to RFC 2368:
Credit: https://stackoverflow.com/a/13415988/1835519