【问题标题】:How to get wordpress post author email in qoutes如何在引号中获取wordpress帖子作者电子邮件
【发布时间】:2014-05-16 07:18:03
【问题描述】:

我正在尝试在 single.php 页面上以“myeamil@live.com”之类的引用获取 wordpress 帖子作者电子邮件。

其实我想给发这个帖子的那个作者发邮件。

我正在使用 wp_mail 功能从 single.php 页面向作者发送电子邮件。

这是我正在使用的变量,但它正在获取管理员电子邮件。

$emailTo = get_option('admin_email');

我想要发布帖子的作者电子邮件,而不是管理员电子邮件。我需要帮助。非常感谢。

更新

这是我正在尝试做的代码

if(!isset($hasError)) { //$emailTo = "w_chand@live.com";如果 (!isset($emailTo) || ($emailTo == '') ){ $emailTo = the_author_meta('user_email'); } $subject = '邮件主题去 这里'.$name; $body = " 名称:$Name nnDuration:$duration nnComments: $cmets ";

$headers = "回复:'".$name."' rn";如果(wp_mail($emailTo, $subject, $body, $headers)){

echo "查询已发送成功"; } else { echo "邮件功能错误!"; }

【问题讨论】:

    标签: php wordpress email


    【解决方案1】:

    您可以通过get_the_author_meta() wordpress 函数获取作者邮箱。

    <?php 
          $user_email = get_the_author_meta('user_email');
    ?>
    

    获取用户 ID 25 的电子邮件地址,并使用他们的显示名称作为锚文本回显它。

    <p>Email the author: 
         <a href="mailto: 
              <?php echo get_the_author_meta('user_email', 25); ?>"
         >
              <?php the_author_meta('display_name', 25); ?>
         </a>
    </p>
    

    以下功能已弃用

     <?php the_author_email(); ?> 
    

    邮件链接

    将作者电子邮件地址显示为“mailto”链接。

    <a href="mailto:<?php the_author_email(); ?>">Contact the author</a>
    

    演示代码

    <div id="about-author-wrap">
         <div class="about-author-avatar">
            <?php echo get_avatar( get_the_author_email(), '90' ); ?>
         </div>
         <div class="about-author-info">                                
            <h5>About the Post Writer <small>View all posts by <?php the_author_posts_link(); ?></small></h5>
        </div>
        <div class="about-author-description">
            <?php the_author_meta("description"); ?>
        </div>
    </div>
    

    希望对您有所帮助!

    【讨论】:

    • 谢谢。但它是在用户电子邮件中登录的。实际上它应该是发帖者的作者电子邮件。
    • 所以您想通过登录的用户电子邮件地址获取作者电子邮件。
    • 据你说是&lt;?php $emailTo = the_author_email(); ?&gt;,我如何在引号中输出以发送电子邮件?
    • 当您在使用帖子模板时发布正文结尾部分时,您设置了当时的作者信息,您可以使用此设置此电子邮件地址。
    • 我知道。我只是想通过报价发送电子邮件。
    【解决方案2】:

    试试下面的代码。 Reference page。希望对您有所帮助。

    <?php $user_email = get_the_author_meta('user_email'); ?>
    

    【讨论】:

      【解决方案3】:

      尝试:

       $emailTo = '"'.the_author_meta('user_email').'"';
      

      【讨论】:

      • 谢谢。我做到了,得到了Mail function Error!
      • 请对所有数据使用单引号,如下所示: wp_mail( 'me@example.net', 'The subject', 'The message' );因此对于 $emailTo,试试这个:$emailTo = "'".the_author_meta('user_email')."'";
      • 我做了兄弟。仍然是邮件功能错误。我坚持下去:(
      猜你喜欢
      • 1970-01-01
      • 2016-07-05
      • 1970-01-01
      • 2017-08-09
      • 2013-10-11
      • 1970-01-01
      • 1970-01-01
      • 2021-02-06
      • 1970-01-01
      相关资源
      最近更新 更多