简体   繁体   English

WordPress,通过电子邮件发送页面的某些部分

[英]WordPress, Email certain part of the page

I'm currently developing a page which needs certain parts of the content to be emailed to myself. 我目前正在开发一个页面,该页面需要将某些内容的一部分通过电子邮件发送给我自己。

In the code, is a loop, which gets all the information, so it would need to literally be a copy of the text on their screen. 在代码中,是一个循环,它获取所有信息,因此实际上需要在屏幕上复制文本。

I did try the following: 我确实尝试了以下方法:

<a href="mailto:email@emailaddres.com?subject=Test&body=<?php urlencode(the_permalink()) ?>">Email this link to a friend </a>

which emailed myself only the link to the page, which would not work as the information will be saved using cookies. 会仅通过电子邮件向自己发送指向该页面的链接,该链接将无法使用,因为该信息将使用Cookie进行保存。

Does anyone have any ideas how to do this, maybe by only emailing the content in a certain class? 有没有人有任何想法如何做到这一点,也许只是通过电子邮件发送特定班级的内容?

EDIT 编辑

    <script type="text/javascript">
$( document ).ready(function() {
   function getContent() {
  var a = document.getElementsByClassName('email-class');
  var b = "";
  for (var i = 0; i < a.length; i++) {
    b+=a[i].innerHTML;
  }
  return b;
}
});

</script>
        <div id="primary" class="content-area container">
            <main id="main" class="site-main" role="main">

                <div class="row">

                    <div class="col-md-12">


                        <div class="email-class">
                        <h1><?php the_title(); ?></h1>
                        <p><?php echo do_shortcode('[user_favorites user_id="" include_links="true" site_id="" post_types="" include_buttons="false"]');?></p>
                        </div>
<a href="mailto:email@emailaddres.com?subject=Test&body=" onclick="this.href += getContent();">Email this content to a friend </a>


                </div>

            </main><!-- .site-main -->
        </div><!-- .content-area -->

Does anyone have any ideas how to do this, maybe by only emailing the content in a certain class? 有没有人有任何想法如何做到这一点,也许只是通过电子邮件发送特定班级的内容?

function getContent() {
  var a = document.getElementsByClassName('your-class');
  var b = "";
  for (var i = 0; i < a.length; i++) {
    b+=a[i].innerHTML;
  }
  return b;
}

from https://stackoverflow.com/a/11666892/1124793 来自https://stackoverflow.com/a/11666892/1124793

The function will return a string of all the content in the class 'your-class' . 该函数将返回类'your-class'中所有内容的字符串。 You can then email it to yourself using the method you tried: 然后,您可以使用尝试的方法通过电子邮件将其发送给自己:

<a href="mailto:email@emailaddres.com?subject=Test&body=" onclick="this.href += getContent();">Email this content to a friend </a>

This will append the content you get from getContent() from above onto the mailto link you originally tried and therefore put it into the body field of whatever email client you're using. 这会将您从getContent()上方获得的内容附加到您最初尝试的mailto链接上,因此将其放入您正在使用的任何电子邮件客户端的主体字段中。

Well, this could work out for you: 好吧,这可能为您解决:

index.php index.php

<html>
    <head>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
    </head>
    <body>
        <a onclick="send()" id="email_content">Content to be derlivered</a>
        <script>
            $(function(){
                function send(){
                    var inside_html = $("#email_content").html();
                    $.post("send.php", {data: inside_html}, function(data){console.log("success");});
                }
            });
        </script>
    </body>
</html>

send.php send.php

<?php
if(isset($_POST)){
    //reference here for more details in mail() - http://php.net/manual/en/function.mail.php
    $html = $_POST["data"];
    $to = "CHANGE THIS";
    $subject = "CHANGE THIS TOO";
    $body = $html;
    $headers = "FROM: `PLACE-YOUR-EMAIL-ADDRESS-HERE`\n";
    mail($to, $subject, $body, $headers);
}
?>

Suggested reading - http://api.jquery.com/jquery.post/ 建议阅读-http://api.jquery.com/jquery.post/

http://php.net/manual/en/function.mail.php http://php.net/manual/zh/function.mail.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM