简体   繁体   中英

How to get wordpress post author email in qoutes

I am trying to get wordpress post author email in a quote like "myeamil@live.com" on single.php page.

Actually I wanna send email to that author who posted this post.

I am using wp_mail function to send email to author from single.php page.

Here is the variable i am using but it is getting admin email.

$emailTo = get_option('admin_email');

Instead of admin email I want author email who posted the post. I need help please. Many thanks.

Update

Here is my code i am trying to do

if(!isset($hasError)) { //$emailTo = "w_chand@live.com"; if (!isset($emailTo) || ($emailTo == '') ){ $emailTo = the_author_meta('user_email'); } $subject = 'email subject goes here'.$name; $body = " Name: $Name nnDuration: $duration nnComments: $comments ";

$headers = "Reply-To: '".$name."' rn"; if(wp_mail($emailTo, $subject, $body, $headers)){

echo "Enquiry has been sent successfully"; } else { echo "Mail function Error!"; }

You can get by get_the_author_meta() wordpress function to get author email address.

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

Get the email address for user ID 25, and echo it using their display name as the anchor text.

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

Following function is deprecated ,

 <?php the_author_email(); ?> 

Mailto Link

Displays author email address as a "mailto" link.

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

Demo Code

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

Hope this help you!

Try below code. Reference page . Hope it helps.

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

尝试:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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