我可以使用mailto:设置电子邮件的主题/内容吗?

html HTML

Davaid神无

2020-03-16

使用mailto:时是否可以设置电子邮件的主题/内容?

第1833篇《我可以使用mailto:设置电子邮件的主题/内容吗?》来自Winter(https://github.com/aiyld/aiyld.github.io)的站点

11个回答
王者一打九银 2020.03.16

Note that it is not possible to use HTML in the message body, according to RFC 2368:

The special hname "body" indicates that the associated hvalue is the body of the message. The "body" hname should contain the content for the first text/plain body part of the message. The mailto URL is primarily intended for generation of short text messages that are actually the content of automatic processing (such as "subscribe" messages for mailing lists), not general MIME bodies.

Credit: https://stackoverflow.com/a/13415988/1835519

Itachi猿 2020.03.16

Yes, you can like this:

mailto: email@host.com?subject=something
老丝飞云 2020.03.16

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.

神无小胖Pro 2020.03.16

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>
JimGil前端 2020.03.16

我将其分成几行以使其更具可读性。

<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>
梅达蒙 2020.03.16

我创建了一个开源工具来简化此过程。输入您想要的字符串,您将立即获得mailto

mailto.now.sh

Template지️模板中的完整电子邮件

网站演示

Davaid番长十三 2020.03.16
mailto:joe@company.com?subject=Your+subject
理查德阳光 2020.03.16

您可以使用以下任一种方式将添加的主题添加到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标签

Harry小小 2020.03.16

mailto:URL方案定义在RFC 2368另外,在RFC 1738RFC 3986中定义了将信息编码为URL和URI的约定这些规定了如何将bodysubject标头包含在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&amp;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>";
?>
GOMandy 2020.03.16
<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>

您可以使用此代码设置主题,正文,抄送,密件抄送

Itachi小哥 2020.03.16

是的,请使用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>

正如评论中提到的那样subjectbody必须适当地进行转义。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

问题类别

JavaScript Ckeditor Python Webpack TypeScript Vue.js React.js ExpressJS KoaJS CSS Node.js HTML Django 单元测试 PHP Asp.net jQuery Bootstrap IOS Android