Trigger email send after custom post publish

I have a custom post type set up so that a user in the role of contributor can create a post, but an administrator has to approve the post and publish it.

I’d like to hook into the event when the administrator publishes this post type and then send an email to all contributors that there has been a post.

I tried a test email to myself hooking off of ‘save_post’ when publishing a post and it worked, but I got sent five emails. There’s no loop in the function:

add_action( 'save_post', 'clr_test_email' );

function clr_test_email($post_id) {

   mail("myemail@gmail.com","
   ok hooked into save post","Testing save post trigger".$post_id,"From: crou@zzz.com\r\nContent-Type: text/plain;charset=utf-8");

}

So I’m not sure if ‘save_post’ is my best bet.

There used to be a ‘publish_post’ hook, but according to the Codex it has been deprecated.

Any thoughts?

Solutions Collecting From Web of "Trigger email send after custom post publish"

When hooking on to save_post you need to check that it’s not a revision & is not WP autosaving the data..

You’ll need this code before you send the email so it returns if it’s autosaving or is a post revision.

if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) {
    return;
}
if ( wp_is_post_revision( $post_id ) ) {
    return;
}

The post revision one is the first example on this page: http://codex.wordpress.org/Plugin_API/Action_Reference/save_post