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


当前回答

诀窍在这里 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: URL方案在RFC 2368中定义。此外,在RFC 1738和RFC 3986中定义了将信息编码为url和uri的约定。它们规定了如何将正文和主题标题包含到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&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>";
?>

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

邮件主题示例:

<a href=“mailto:no-one@snai1mai1.com?主选=免费巧克力">example</a>

邮件内容:

<a href="mailto:no-one@snai1mai1.com?subject=看这个网站&body=嗨,我发现了这个网站,认为你可能会喜欢它http://www.geocities.com/wowhtml/">告诉一个朋友</a>

正如注释中提到的,主体和主体都必须正确转义。使用encodeURIComponent(subject),而不是针对特定情况手工编码。

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

%0D%0A // one line break

如果你想添加html内容到你的电子邮件,url编码你的html代码的消息体,并包括在你的mailto链接代码,但问题是你不能设置电子邮件的类型从明文到html,客户端使用链接需要他们的邮件客户端默认发送html电子邮件。如果你想测试的话,这里有一个简单的mailto链接的代码,链接中包含一个图像(添加angular风格的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编码的。

mailto:joe@company.com?subject=Your+subject

是的,你可以这样做:

mailto: email@host.com?subject=something