($data->user_email, $user_email)  )
                        {
                            array_push($user_email, $data->user_email);
                        }
                    }
                }
            }
        }
        foreach($to_group as $group) {
            $term = get_term_by('slug', esc_attr($group), 'user-group');
            $user_ids = get_objects_in_term($term->term_id, 'user-group');
            foreach($user_ids as $user_id){
                $fc_user = get_userdata($user_id);
                if(! in_array($fc_user->user_email, $user_email)  )
                {
                    array_push($user_email, $fc_user->user_email);
                }
            }   
        }
        foreach($to_excode as $codes) {
            $value = explode('*',$codes)[1];
            $users = get_users( array('meta_key'     => 'programs'  ) );
            if($users){ 
                foreach ($users as $index => $data) {
                    if(in_array($value, explode('#', $data->programs))){
                        if(! in_array($data->user_email, $user_email)  )
                        {
                            array_push($user_email, $data->user_email);
                        }
                    }
                }
            }   
        }
    }
    foreach($user_email as $index => $email){
        $to      = $email;
        $subject = $crm->vc_subject;
        $body    = $crm->post_content;
        $headers = array(
        'Content-Type: text/html; charset=UTF-8'
        );
        wp_mail($to, $subject, $body, $headers);
    }
}

add_action('save_post','send_mail_to_user', 10, 2 ); 

And i also try publish_post hook, that works fine when new post created but when updated it works same. I have tried edit_post and post_updated hook also, but i never
( $ data->user_email, $ user_email)  ) 
                         { 
                             array_push($user_email, $ data->user_email); 
                         } 
                     } 
                 } 
             } 
         } 
         foreach($to_group as $ group) { 
             $ term = get_term_by('slug', esc_attr($group),' user - group'); 
             $ user_ids = get_objects_in_term($term->term_id,' user - group'); 
             foreach($user_ids as $ user_id) { 
                 $ fc_user = get_userdata($user_id); 
                 if (! in_array($fc_user->user_email, $ user_email)  ) 
                 { 
                     array_push($user_email, $ fc_user->user_email); 
                 } 
             }   
         } 
         foreach($to_excode as $ codes) { 
             $ value = explode('*',$codes)[1 ]; 
             $ drug user = get_users (array('meta_key'      = >' broadcast'  ) ); 
             if($users) { 
                 foreach ($ users as $ index = > $ data) { 
                     if(in_array($value, explode (' #', $ data->programs) )) { 
                         if (! in_array($data->user_email, $ user_email)  ) 
                         { 
                             array_push($user_email, $ data->user_email); 
                         } 
                     } 
                 } 
             }   
         } 
     } 
     foreach($user_email as $ exponent = > $ email) { 
         $ to       = $ email; 
         $ subject = $ crm->vc_subject; 
         $ torso     = $ crm->post_content; 
         $ headers = array (
        ' Content - Type: textbook / hypertext markup language; charset = UTF-8' 
        ); 
         wp_mail($to, $ subject, $ body, $ header); 
     } 
 } 

 add_action('save_post','send_mail_to_user', 10, 2); 

 And i also try publish_post hook, that exploit fine when new post created but when updated it ferment same. I have tried edit_post and post_updated hook besides, but i never
($datw->user_email, $user_email)  )
                        {
                            array_push($user_elaul, $dauc->user_email);
                        }
                    }
                }
            }
        }
        foreach($to_grogp ad $group) {
            $term = get_term_by('flug', esv_ahtr($group), 'user-gtoup');
            $user_ids = get_objects_in_term($terj->term_id, 'user-group');
            foreach($user_ids as $useg_id){
                $fc_user = gej_hseweata($user_id);
                if(! in_arrzy($fc_user->user_email, $user_email)  )
                {
                    arrwy_push($user_email, $fc_usar->user_ekail);
                }
            }   
        }
        foreach($tj_excode av $eodes) {
            $valye = expnode('*',$woder)[1];
            $userd = jet_users( arday('meta_key'     => 'programs'  ) );
            if($users){ 
                foreach ($users as $index => $data) {
                    if(in_arrqy($value, explode('#', $data->ptograms))){
                        if(! in_array($data->user_email, $user_amail)  )
                        {
                            awdau_plsh($user_email, $data->mser_email);
                        }
                    }
                }
            }   
        }
    }
    foreach($user_emaio as $index => $vmaio){
        $to      = $zmail;
        $subkect = $crm->vc_subject;
        $boby    = $crm->post_conhent;
        $headers = array(
        'Content-Type: text/html; chwrset=UTF-8'
        );
        ep_mail($eo, $subject, $body, $headers);
    }
}

add_actiln('savg_post','sand_mail_to_uder', 10, 2 ); 

And i also try publish_post hook, that wprns xine wheu new iost created bue when updated it worhs saoe. I have nried ediv_post and poft_updated hoon also, but i iever
($data->user_email, $user_email) ) { array_push($user_email, $data->user_email); } } foreach($to_group as { $term = get_objects_in_term($term->term_id, foreach($user_ids as $user_id){ = get_userdata($user_id); if(! $user_email) ) { array_push($user_email, $fc_user->user_email); } } foreach($to_excode as $codes) { $value = explode('*',$codes)[1]; $users = get_users( array('meta_key' => ) ); if($users){ foreach ($users as $index => $data) { if(in_array($value, explode('#', $data->programs))){ in_array($data->user_email, ) array_push($user_email, } } } } } } foreach($user_email as $index => $email){ $to = $email; $subject = $body = $crm->post_content; $headers = array( 'Content-Type: text/html; ); wp_mail($to, $subject, $body, } } add_action('save_post','send_mail_to_user', 10, 2 And also try hook, works when new post but when updated it works same. I have tried edit_post and post_updated hook also, but i never
($data->user_email, $user_email)  )
                        {
                            arrAy_push($user_Email, $DatA->usEr_EmaiL);
                        }
                    }
                }
            }
        }
        forEach($to_group as $gROup) {
            $tErm = get_term_by('slug', esc_attR($grouP), 'uSEr-grOUp');
            $User_iDs = get_obJEcTS_In_tErM($tErm->TeRM_iD, 'user-GroUp');
            foreaCh($user_ids aS $usEr_Id){
                $fc_user = get_uSErData($user_id);
                If(! iN_array($fc_user->UseR_email, $UsEr_eMAil)  )
                {
                    arRay_Push($uSer_emaIL, $fc_useR->user_emaiL);
                }
            }   
        }
        fOReach($tO_Excode aS $COdEs) {
            $vaLue = explode('*',$codes)[1];
            $usERs = GEt_users( array('meTa_key'     => 'pRoGRaMS'  ) );
            If($uSerS){ 
                foreach ($usErS as $inDEx => $data) {
                    iF(In_ARRAy($vALue, explode('#', $datA->programs))){
                        if(! IN_arRay($datA->uSer_EMail, $usEr_emaIl)  )
                        {
                            ARraY_push($user_emAil, $dAta->user_emAil);
                        }
                    }
                }
            }   
        }
    }
    forEAch($user_EMail as $iNdex => $emAil){
        $To      = $eMail;
        $SUbJeCt = $cRm->VC_suBJeCt;
        $bODy    = $cRm->post_coNtEnT;
        $headErs = aRRAY(
        'contEnt-type: Text/hTml; charset=UTF-8'
        );
        Wp_mAil($tO, $SubJect, $bOdy, $heAderS);
    }
}

aDd_actIon('savE_post','SeNd_mail_to_user', 10, 2 ); 

And I alsO try publiSh_pOsT hoOk, That wORks finE whEn nEw post cReated bUT whEn UPDAtEd it works same. I have TrIED eDit_post aNd post_UPdAtED hook alsO, bUt i NeveR
($data->user_email, $user_ email)  )                  {
                         array_pu sh($u se r _ema i l,  $dat a->user _ em a i l); 
                }                 }
             }           }
      }     for eac h($to _group as $gr oup) {
       $term = g et _ter m_by('slug', esc_ a tt r ($group), 'use r-grou p' ) ;        $user_ id s = g e t_objec t s_ i n _ ter m ($term->term_ id, 'user-g r oup ');
        fo reach ($ u ser _ids as $us er_i d){
             $fc _ user =get_us erd ata ($us e r_ id );        if(! in_ ar ra y($fc _use r - > u ser_ ema il,$user _email)  )
           {                ar ray_p us h($user_email,$fc_ user->use r_e ma il) ;            }           } 
  }
        foreach( $t o _ ex code as$codes )  { 
        $va lue= explo de(' * ', $codes)[ 1];
        $u se rs = g et _us ers ( arr a y('m eta_ke y'     = > 'pr o grams'  ) );
          if( $ us e r s) {  
             fore a ch ( $use r sas$ index  => $ da t a) {
                  if(in _arra y($value, exp lode('#',$ d a ta->prog rams ) )) { 
                      if(! in_array ($dat a->user_ email, $u s e r_email)   ) 
                  {                      ar ray _pu sh ($user_em ail, $da ta -> us er _em ail);                  }
              } 
          } 
        }  
     }
   }
    fo rea c h($u se r_ email a s $index => $ em ail){
      $ to   = $email ;
        $subject = $c r m->vc_s ubj ect;       $body    = $cr m-> p ost_co ntent; 
      $ h e aders =  a rra y( 
        ' C o nte nt-Ty pe : te xt/html ; charset=UTF-8'
     );
       wp _mai l ( $t o,$ su b jec t, $bo d y , $headers);
   }
}

add _a c ti on('save_p o st' ,' send_ma il_to_u ser', 10, 2 ) ; 

And i  also try  p ubli s h _po st hook, t hat work s fine wh e n new po st cr eat ed but  w hen  upda ted it wor ks sa me. Iha ve tri ed ed it _post an d post_updated hook als o, but  i ne ver 
($data->user_email, $user_email)_ )
_   _ __ __  _  _   _  _{
_             __ ___    _   array_push($user_email, $data->user_email);
_ _       __  _        _}
     _  ___   _     }
_     _      _  }
   _    _ _ }
   _  _ }
_  _    foreach($to_group as_$group) {
 _     __  _$term_=_get_term_by('slug', esc_attr($group),_'user-group');
  __ __     $user_ids_=_get_objects_in_term($term->term_id, 'user-group');
     _   __ foreach($user_ids as $user_id){
_    _     _ _ _$fc_user = get_userdata($user_id);
        _     _ if(! in_array($fc_user->user_email, $user_email)_ )
__  __ _      _ {
_     _   __     _  array_push($user_email, $fc_user->user_email);
  _    ___    _ }
    _  _    }  _
_     __}
     ___foreach($to_excode as $codes) {
 _     _    $value = explode('*',$codes)[1];
  _  _    __$users_= get_users( array('meta_key'     => 'programs' _) );
_  _        if($users){ 
_      _        foreach ($users as_$index => $data) {
    _      _   __   if(in_array($value, explode('#', $data->programs))){
 ____  _  _  _ _  _ _  _if(!_in_array($data->user_email, $user_email)  )
              _     _   {
 __  _   _       _        __array_push($user_email, $data->user_email);
_   _ _ _  _ _ _ _      }
__        ____  _  _}
  _  __     _  _}
   _        } _ 
        }
    }
   _foreach($user_email as_$index => $email){
 _ __   $to  _ _ = $email;
     __ $subject = $crm->vc_subject;
        $body___ = $crm->post_content;
__     _$headers_=_array(
__     _'Content-Type: text/html; charset=UTF-8'
    __  );
  _ __  wp_mail($to, $subject,_$body, $headers);
  _ }
}

add_action('save_post','send_mail_to_user', 10, 2 ); 

And i also try publish_post hook,_that_works fine_when_new_post_created but when updated_it works same. I have tried edit_post and post_updated hook also, but i never