I used the save_post_CPT() hook for doing this.
I can’t remember if it sent the content the first time though:
try this code:
function my_project_rt_send_email( $post_id ) {
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return;
// If this is just a revision, don't send the email.
//if ( wp_is_post_revision( $post_id ) )
// return;
// only go if user checked media submission box.
if(isset($_POST['media-submit'])){
$post_title = get_the_title( $post_id );
$post_url = get_permalink( $post_id );
$post_content = get_the_content( $post_id );
$content_post = get_post( $post_id );
$content = $content_post->post_content;
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
$subject="Important - A NEW POST FOR YOU";
$headers = array('Content-Type: text/html; charset=UTF-8');
$headers[] = 'From: YOUR SITE <[email protected]>';
// COPY USER BASED ON FIELD SEND TO USER BASED ON FIELD
if( get_field('distribution_email') )
$headers[] = 'Bcc: '. get_field('distribution_email');
$message = "<h3>".$post_title."</h3>";
$message .= $content;
$message .= '<a href="'. $post_url.'">'.$post_title.'</a>';
// Send email to admin.
wp_mail( '[email protected]', $subject, $message, $headers);
}
}
add_action( 'save_post_my_cpt', 'my_project_rt_send_email' );
You’ll want to change the “save_post_MYCPT” to your cpt name, change the to email, and the from in the first header array addition.
I don’t know if your to field is a select or if text field, in this case it’s a text, so you may need to change that as well.
Also I had a media check box in mine so maybe remove the
if(isset($_POST['media-submit'])){
and the attached its attached closing bracket “}” too since you need them.