I am running this in my localhost. when i publish a post nothing happens. I have added this in my themes functions.php file. How do i check the error? I dont see any error. I am new to development.
add_action('publish_post', 'sendnotification');
function sendnotification($post_id) {
$post = get_post($post_id);
$author = get_userdata($post->post_author);
// $user_email = get_the_author_meta( 'user_email' , $author_id );
$subject = "Post Published: ".$post->post_title."";
$message = "
Hi ".$author->display_name.",
Your post, \"".$post->post_title."\" has just been published.
View post: ".get_permalink( $post_id )."
Thanks"
;
$sent = wp_mail($author->user_email, $subject, $message);
if($sent) {
echo "sent";
}//mail sent!
else {
echo "failed";
}//message wasn't sent
}