Dear Jamal,
thanks. I will send you the fill code of the function so that you have a better picture. The $post_id contains the id of the post and all other line do work. One mail to the author gets send, but not the one to the address from the custom field as the custom field does not get grabbed.
function send_email_notification( $new_status, $old_status, $post ){
$post_ID=$post->ID;
$postType=get_post_type($post_ID);
if($postType=="post" or $postType=="cb-ots-post"){
if ( 'publish' !== $new_status )
return;
if('publish' != $old_status){
$meta_values = get_post_meta($post_ID, 'is_notified', true);
if($meta_values!='yes'){
$pub_post = get_post($post_ID);
$author_id=$pub_post->post_author;
$post_title=$pub_post->post_title;
$postperma=get_permalink( $post_ID );
$user_info = get_userdata($author_id);
$usernameauth=$user_info->user_login;
$user_nicename=$user_info->user_nicename;
$user_email=$user_info->user_email;
$first_name=$user_info->user_firstname;
$last_name=$user_info->user_lastname;
$blog_title = get_bloginfo('name');
$siteurl=get_bloginfo('wpurl');
$siteurlhtml="$siteurl";
// Toolset: gran CF with address
$to_cf_post = get_post_meta($post_ID, 'wpcf-ots-notify-empfanger', true);
$publish_post_notification_settings=get_option('publish_post_notification_settings');
$subject=$publish_post_notification_settings['subject'];
$from_name=$publish_post_notification_settings['from_name'];
$from_email=$publish_post_notification_settings['from_email'];
$emailBody=$publish_post_notification_settings['emailBody'];
$emailBody=stripslashes($emailBody);
$emailBody=stripslashes(htmlspecialchars_decode($emailBody));
$charSet=get_bloginfo( "charset" );
$mailheaders='';
$mailheaders .= "Content-Type: text/html; charset=\"$charSet\"\n";
$mailheaders .= "From: $from_name <$from_email>" . "\r\n";
$emailBody=wpautop($emailBody);
$emailBody='<!DOCTYPE html><html '.get_language_attributes().'><head> <meta http-equiv="Content-Type" content="text/html; charset='. get_bloginfo( "charset" ).'" /><title>'.get_bloginfo( 'name', 'display' ).'</title></head><body>'.$emailBody
.'<br>'
.'<br>Post_ID: ' .$post_ID
.'<br>to_email: ' .$to_email
.'<br>to_cf_post: ' .$to_cf_post
.'</body></html>';
// Mail to author of post: works
$Rreturns=wp_mail($user_email, $subject, $emailBody, $mailheaders);
if($Rreturns){
add_post_meta($post_ID, 'is_notified', 'yes');
}
//2nd Mail to address from Custom Field: does not work as no value got grabbed
if ($to_cf_post != "" ) {
$Rreturns=wp_mail($to_cf_post, $subject, $emailBody, $mailheaders);
}
}
}
}
}