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

时间:2011-01-24 12:41:09

标签: html email mailto

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

13 个答案:

答案 0 :(得分:1357)

是的,请查看mailto:http://www.angelfire.com/dc/html-webmaster/mailto.htm

的所有提示和技巧

mailto主题示例:

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

mailto with content:

<a href="mailto:?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),而不是针对特定情况进行手工编码(例如%0A用于换行符。)

答案 1 :(得分:110)

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

您可以使用此代码设置subject,body,cc,bcc

答案 2 :(得分:32)

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

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

具体而言,您必须对电子邮件地址,主题和正文进行百分比编码,并将其置于上述格式中。百分比编码的文本在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>";
?>

答案 3 :(得分:23)

您可以使用以下任一方法添加添加到mailto命令的主题。 添加?subject mailto到mailto标签。

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

我们还可以通过在标记的末尾添加&amp; body来在邮件正文中添加文本,如下例所示。

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

除了正文外,用户还可以输入&amp; cc或&amp; 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>

How to add subject to mailto tag

答案 4 :(得分:12)

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

答案 5 :(得分:8)

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

答案 6 :(得分:7)

是的:

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

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

您甚至可以指定很少知道和使用的元素:cc,bcc,来自电子邮件。

答案 7 :(得分:7)

我将它分成不同的行,使其更具可读性。

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

答案 8 :(得分:6)

是的,你可以这样:

mailto: email@host.com?subject=something

答案 9 :(得分:5)

请注意,根据RFC 2368

,无法在邮件正文中使用HTML
  

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

信用:https://stackoverflow.com/a/13415988/1835519

答案 10 :(得分:1)

如果您想在电子邮件中添加html内容,url会对邮件正文的html代码进行编码并将其包含在您的mailto链接代码中,但是您无法通过明文设置此链接的电子邮件类型对于html,使用该链接的客户端需要他们的邮件客户端默认发送HTML电子邮件。如果你想在这里测试的是一个简单的mailto链接的代码,一个图像包含在一个链接中(为了可见性添加了角度样式的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编码的。

答案 11 :(得分:1)

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

class Step3JobSummaryVC: UIViewController {

    let videoPlayer = VideoPlayer(video: Video.step3JobsSummary)

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)

        videoPlayer.start(on: self)
    }
}

final
class VideoPlayer {
    private var initialLaunch: Bool = true
    private let playerVC = AVPlayerViewController()
    private let video: Video

    init(video: Video) {
        self.video = video
    }

    func start(on viewController: UIViewController) {
        if initialLaunch == true {
            showUnplayedVideo(on: viewController)
            initialLaunch = false
        }

        Video.updatePlaybackTime(playerVC: playerVC, videoURL: video.url, firebaseVideoID: video.firebaseID)
    }

    func showUnplayedVideo(on viewController: UIViewController) {

        // 1. get current video data
        Video.getFirebaseData(firebaseVideoID: video.firebaseID) { (playbackTime, watched) in

            if !watched {

                // 2. show setup video popup on first load
                guard let videoURL = URL(string: self.video.url) else { print("url error"); return }
                let player = AVPlayer(url: videoURL)

                self.playerVC.player = player

                // 3. fast forward to where user left off (if applicable)
                player.seek(to: CMTimeMakeWithSeconds(playbackTime, preferredTimescale: 1))

                // 4. dismiss the player once the video is over and update Firebase
                NotificationCenter.default.addObserver(self,
                                                       selector: #selector(self.playerDidFinishPlaying),
                                                       name: NSNotification.Name.AVPlayerItemDidPlayToEndTime,
                                                       object: self.playerVC.player?.currentItem)

                viewController.present(self.playerVC, animated: true) {
                    self.playerVC.player?.play()
                }
            }
        }
    }

    @objc func playerDidFinishPlaying(note: NSNotification) {
        self.playerVC.dismiss(animated: true)
        Video.updateFirebase(firebaseVideoID: video.firebaseID)
    }
}
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);
});

答案 12 :(得分:0)

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

mailto.now.sh

  

⚡️mailto中的完整电子邮件模板

website demo

相关问题