Q:

Wordpress: Don't manage to retrieve author's name from php function

I'm creating a function that sends an email to a mailing list when a post is published on my WordPress blog. 
function announce_post($post_id){
    $email_address = 'address.of@the-mailing.list';

    $subject = "New Post: " .  get_the_title($post_id);
    $body = "Hi,\r\n\r\n" . 
        "SOMEONE has just published the article \"" .  
        get_the_title($post_id) . "\"  on \"BLOG TITLE\".\r\n\r\n" .      
        "You can read it at " .  get_permalink($post_id) . " \r\n" . 
        "or visit BLOG_ADDRESS.\r\n\r\n" . 
        "Best wishes\r\n" . 
        "The Publisher";

    if (wp_mail($email_address, $subject, $body, "From: \"BLOG TITLE\" <address.of@the-blog>")) { }
}

add_action('publish_post','announce_post');

As it is the function works well, but of course I would replace the SOMEONE with the actual post's author name.  And I don't manage to retrieve that. 
Neither get_the_author($post_id), get_post_meta($post_id, 'author_name', true) nor anything else I tried and can't recall worked.  Everything just returned "". 
So what is the correct way to retrieve the post author's name, given a post id? 

A:

get_the_author() is a (perhaps misleading) function that is intended for use in the loop.  It's only parameter is now deprecated.  It's also worth noting that author data is not stored as post meta, so any get_post_meta attempts will be in vain. 
You should in fact use get_the_author_meta( 'display_name', $author_id ).  I would suggest accepting the second argument in your hook, which is the $post object, to obtain the author ID:
function announce_post( $post_id, $post ) {
    $name = get_the_author_meta( 'display_name', $post->post_author );
}

add_action( 'publish_post','announce_post', 10, 2 );

