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

是否可以设置邮件的主题/内容,当我使用mail to:?

1012552 次浏览

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

邮件主题示例:

<a href="mailto:no-one@snai1mai1.com?subject=free chocolate">example</a>

mailto with content:

<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),而不是针对特定情况手动编码。

正如注释中提到的连帽衫,您可以通过在字符串中添加以下编码序列来添加换行符:

%0D%0A // one line break
mailto:joe@company.com?subject=Your+subject

是的,你可以像这样:

mailto: email@host.com?subject=something
<a href="mailto:manish@simplygraphix.com?subject=Feedback forwebdevelopersnotes.com&body=The Tips and Tricks section is great&cc=anotheremailaddress@anotherdomain.com&bcc=onemore@anotherdomain.com">Send me an email</a>

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

您可以使用以下任一方法将主题添加到mail to命令中。

添加?主题out mail to到mail to标记。

<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">ThirdExample</a>

如何将主题添加到mail标签

这就是诀窍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>

有:

使用这个来试验mail to表单元素和链接编码。

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

您甚至可以指定很少知道和使用的元素:cc、bcc、from email。

我把它分成几行,使它更具可读性。

<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>

如果您想将html内容添加到您的电子邮件中,url对邮件正文的html代码进行编码,并将其包含在您的mail to链接代码中,但问题是您无法将此链接中的电子邮件类型从纯文本设置为html,使用该链接的客户端默认需要他们的邮件客户端发送html电子邮件。如果您想在这里测试一个简单的mail to链接的代码,其中包含一个链接中的图像(为可见性添加了角度样式的URL):

<a href="mailto:?body=%3Ca%20href%3D%22\{\{ scope.url }}%22%3E%3Cimg%20src%3D%22\{\{ scope.url }}%22%20width%3D%22300%22%20%2F%3E%3C%2Fa%3E">

html标签是url编码的。

请注意,根据rfc2368,无法在消息正文中使用超文本标记语言:

特殊的hname"body"表示相关的hvalue是消息的主体。"body"hname应该包含消息的第一个文本/纯主体部分的内容。mail to URL主要用于生成实际上是自动处理内容的短文本消息(例如邮件列表的"订阅"消息),而不是一般的MIME主体。

图片来源:https://stackoverflow.com/a/13415988/1835519

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

mailto:infobot@example.com?subject=current-issue&body=send%20current-issue

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

<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>";?>

这是一个可运行的代码片段,可帮助您生成带有可选主题和正文的ailto:链接。

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>

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

mailto.now.sh

💌⚡模板邮件中的完整电子邮件

在此处输入图片描述