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.
Get the email address for user ID 25, and echo it using their display name as the anchor text.
Following function is deprecated,
Mailto Link
Displays author email address as a “mailto” link.
Demo Code
Hope this help you!
Try below code. Reference page. Hope it helps.
try: