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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4782068/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 06:20:34  来源:igfitidea点击:

Can I set subject/content of email using mailto:?

htmlemailmailto

提问by Jiew Meng

Is it possible to set the subject/content of email when I use mailto:?

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

回答by Haim Evgi

Yes, look all tips and tricks with mailto: http://www.angelfire.com/dc/html-webmaster/mailto.htm

是的,查看 mailto 的所有提示和技巧:http: //www.angelfire.com/dc/html-webmaster/mailto.htm

mailto subject example:

邮件主题示例:

<a href="mailto:[email protected]?subject=free chocolate">example</a>

mailto with content:

邮件内容:

<a href="mailto:[email protected]?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>

As alluded to in the comments, both subjectand bodymust be escaped properly. Use encodeURIComponent(subject)on each, rather than hand-coding for specific cases.

至于提到的意见,无论是subjectbody必须正确转义。encodeURIComponent(subject)在每个上使用,而不是针对特定情况手动编码。

As Hoodymentioned in the comments, you can add line breaks by adding the following encoded sequence in the string:

正如Hoody在评论中提到的,您可以通过在字符串中添加以下编码序列来添加换行符:

%0D%0A // one line break

回答by oditiwebs.com

<a href="mailto:[email protected]?subject=Feedback for 
webdevelopersnotes.com&body=The Tips and Tricks section is great
&[email protected]
&[email protected]">Send me an email</a>

you can use this code to set subject, body, cc, bcc

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

回答by William Entriken

The mailto:URL scheme is defined in RFC 2368. Also, the convention for encoding information into URLs and URIs is defined in RFC 1738and then RFC 3986. These prescribe how to include the bodyand subjectheaders into a URL (URI):

mailto:URL方案定义在RFC 2368。此外,将信息编码为 URL 和 URI 的约定在RFC 1738RFC 3986 中定义。这些规定了如何将bodysubject标头包含到 URL (URI) 中:

mailto:[email protected]?subject=current-issue&body=send%20current-issue

Specifically, you must percent-encode the email address, subject, and body and put them into the format above. Percent-encoded text is legal for use in HTML, however this URL must be entity encoded for use in an hrefattribute, according to the HTML4 standard:

具体来说,您必须对电子邮件地址、主题和正文进行百分比编码,并将它们放入上述格式中。百分比编码的文本在 HTML 中使用是合法的,但是href根据HTML4 标准,此 URL 必须经过实体编码才能在属性中使用:

<a href="mailto:[email protected]?subject=current-issue&amp;body=send%20current-issue">Send email</a>


And most generally, here is a simple PHP script that encodes per the above.

最普遍的是,这里有一个简单的 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>";
?>

回答by niksmac

You can add subject added to the mailto command using either one of the following ways. Add ?subject out mailto to the mailto tag.

您可以使用以下任一方式添加添加到 mailto 命令的主题。将 ?subject out mailto 添加到 mailto 标记。

<a href="mailto:[email protected]?subject=testing out mailto">First Example</a>

We can also add text into the body of the message by adding &body to the end of the tag as shown in the below example.

我们还可以通过在标签末尾添加 &body 来将文本添加到消息正文中,如下例所示。

 <a href="mailto:[email protected]?subject=testing out mailto&body=Just testing">Second Example</a>

In addition to body, a user may also type &cc or &bcc to fill out the CC and BCC fields.

除了正文之外,用户还可以键入 &cc 或 &bcc 来填写 CC 和 BCC 字段。

<a href="mailto:[email protected]?subject=testing out mailto&body=Just testing&[email protected]&[email protected]">Third
    Example</a>

How to add subject to mailto tag

如何在mailto标签中添加主题

回答by Dawson B

I created an open-source tool for making this easy. Enter the strings you want and you'll instantly get the mailto:

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

mailto.now.sh

邮件到.now.sh

?? Template full emails in a mailto

?? mailto 中的模板完整电子邮件

enter image description here

在此处输入图片说明

回答by payne

mailto:[email protected]?subject=Your+subject

回答by quemeful

I split it into separate lines to make it a little more readable.

我将它分成单独的行以使其更具可读性。

<a href="

    mailto:[email protected]

    ?subject=My+great+email+to+you

    &body=This+is+an+awesome+email

    &[email protected]

    &[email protected]

">Click here to send email!</a>

回答by Arun Kushwaha

回答by woz

Yes:

是的:

Use thisto experiment with mailto form elements and link encoding.

使用来试验 mailto 表单元素和链接编码。

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.

您可以在表单中输入主题、正文(即内容)等,点击按钮并查看可以粘贴到页面中的 mailto html 链接。

You can even specify elements that are rarely known and used: cc, bcc, from emails.

您甚至可以指定很少知道和使用的元素:抄送、密送、来自电子邮件。

回答by MeanEYE

Yes, you can like this:

是的,你可以喜欢这个:

mailto: [email protected]?subject=something