Blog post URL + post title in mailto

时间:2016-08-31 16:47:45

标签: html url blogs mailto

I want to add "share this page via email" button in my blog post page. In the blog post template, this is what I currently have:

<a 
href="mailto:?subject=Post title from XYZ blog&cc=me@xyzblog.com&body=URL+to+page%2C+short+description&<?php
echo curPageURL(); ?>">Share this page via email</a>

How can I make the actual post title and page URL variables correctly appear in the email output?

2 个答案:

答案 0 :(得分:0)

Try

<a href="#" id="mail">Share this page</a>

using

window.onload=function() {
  document.getElementById("mail").onclick=function() {
    this.href='mailto:?subject='+
    document.title+'&cc=me@xyzblog.com&body='+
    document.URL+'%0D%0A'+
    document.querySelector(".s22_richTextContainer").innerText++'%0D%0A'+
    '<img src="'+document.querySelector(".s25img img").src+'" />'
  }
}

You many have to throw a few encodeURIComponent in there

答案 1 :(得分:0)

希望这能帮助在WordPress中开发的人。

以下是我添加到模板文件(.php)

的内容
<a href="mailto:someone@site.com?subject=<?php wp_title()?>&body=<?php 
print(urlencode(get_permalink())); ?>"> Email this blog post... </a>

这篇文章介绍了如何使用Mailto属性:https://css-tricks.com/snippets/html/mailto-links/