問題描述

當我使用 mailto 時,可以設置電子郵件的主題/內容嗎?

最佳解決方案

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

mailto 主題示例:

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

mailto 與內容:

<a href="mailto:?subject=look%20at%20this%20website&body=Hi,I%20found%20this%20websiteand%20thought%20you%20might%20like%20it%20http://www.geocities.com/wowhtml/">tell a friend</a>

次佳解決方案

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

您可以使用此代碼設置主題,正文,cc,bcc

第三種解決方案

您可以使用以下任意一種方法添加添加到 mailto 命令的主題。添加?將郵件發送到 mailto 標籤。

<a href="mailto:test@example.com?subject=testing%20out%20mailto">First Example</a>

我們還可以通過將& body 添加到標籤的末尾,將消息的正文添加到下面的示例中。

 <a href="mailto:test@example.com?subject=testing%20out%20mailto&body=Just%20testing">Second Example</a>

除了身體之外,用户還可以鍵入& cc 或&bcc 來填寫 CC 和 BCC 字段。

<a href="mailto:test@example.com?subject=testing%20out%20mailto&body=Just%20testing&cc=test1@example.com&bcc=test1@example.com">Third
    Example</a>

How to add subject to mailto tag

第四種方案

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

第五種方案

是:

使用 this 來實驗 mailto 表單元素和鏈接編碼。

您可以在表單中輸入主題,正文 (內容) 等,點擊按鈕並查看您可以粘貼到頁面中的 mailto html 鏈接。

您甚至可以指定很少知道和使用的元素:cc,bcc,從電子郵件。

第六種方案

是的,你可以這樣:

mailto: email@host.com?subject=something

第七種方案

這裏是訣竅 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 中定義。此外,將信息編碼為 URL 和 URI 的約定在 RFC 1738 中定義,然後在 RFC 3986 中定義。這些規定了如何將 bodysubject 標頭包含到 URL(URI) 中:

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

具體來説,您必須將電子郵件地址,主題和正文放在 percent-encode 上,並將其放入上述格式。 Percent-encoded 文本適用於 HTML,但根據 HTML4 standard,該 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>";
?>

第九種方案

我把它分成幾行,使它更可讀。

<a href="mailto:johndoe@gmail.com%20%20%20%20?subject=My+great+email+to+you%20%20%20%20&body=This+is+an+awesome+email%20%20%20%20&cc=janedoe@gmail.com%20%20%20%20&bcc=billybob@yahoo.com">Click here to send email!</a>

參考文獻

注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇