Location: PHPKode > projects > News Manager - RSS aggregator > newsmanager/cron_email.php
<?php
for($en=0;$en<count($rssid_email);$en++){
  $rssid_email_new .=$rssid_email[$en].',';
}
$rssid_email_new = rtrim($rssid_email_new,',');

$usr_qry_email="select * from users order by userid asc";
$usr_email_res=$pg_sql->query_pass($usr_qry_email,'4');

for($us=0;$us<count($usr_email_res);$us++)
{
	$user_mail_=$usr_email_res[$us]['email'];
	$user_name_=$usr_email_res[$us]['username'];
		
	$email_qry="select * from popup_settings where userid=".$usr_email_res[$us]['userid']." and settings_name='email'";
	$email_res=$pg_sql->query_pass($email_qry,'4');

	if(count($email_res)>0)
	{
		if($email_res[0]['selected_id']==1){
					$emailall_qry="select * from rssurl_newsitem where url_newsitem_id in (".$rssid_email_new.") order by pubtime desc";
					$emailall_res=$pg_sql->query_pass($emailall_qry,"4");
		 }
		if($email_res[0]['selected_id']==2){
				 $emailall_qry_cat="select newsitem_id from newsitem_category where category_id in (".$email_res[0]['category_id'].") and newsitem_id in (".$rssid_email_new.")";
				 $emailall_qry_cat_res=$pg_sql->query_pass($emailall_qry_cat,"4"); 
					 for($ecat=0;$ecat<count($emailall_qry_cat_res);$ecat++){
						$ecat_id .=$emailall_qry_cat_res[$ecat]['newsitem_id'].',';
					 }
					 $ecat_id =rtrim($ecat_id,',');
				 if($ecat_id !=''){
					 $emailall_qry="select * from rssurl_newsitem where url_newsitem_id in (".$ecat_id.") order by pubtime desc";
					 $emailall_res=$pg_sql->query_pass($emailall_qry,"4");
			 }
		}
		if($email_res[0]['selected_id']==3){
				$emailall_qry="select * from rssurl_newsitem where rss_channel_id in (".$email_res[0]['channel_id'].") and url_newsitem_id in (".$rssid_email_new.") order by pubtime desc ";
 		        $emailall_res=$pg_sql->query_pass($emailall_qry,"4");
		}

		if($email_res[0]['selected_id']==4){
		   $email_tag=explode(",",$email_res[0]['category']);
			for($et=0;$et<count($email_tag);$et++){
			   $email_tag_qry .=" category ='".$email_tag[$et]."' or ";
			}
			  $email_tag_qry =rtrim($email_tag_qry," or ");
			  $emailall_qry="select * from rssurl_newsitem where url_newsitem_id in (".$rssid_email_new.") and (".$email_tag_qry.") order by pubtime desc ";
			  $emailall_res=$pg_sql->query_pass($emailall_qry,"4");
		}

	}//Count Ending
	
if(count($emailall_res)>0 && count($email_res)>0)
{   

	$body .='<table cellpadding="3" align="left" cellspacing="0" border="0">';
	for($pe=0;$pe<count($emailall_res);$pe++){
	$table .='<tr><td valign="top" style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; font-weight: normal; color: #2872AC; text-decoration: none" nowrap>&nbsp;&nbsp;<a style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; font-weight: normal; color: #2872AC; text-decoration: none" href="'.$emailall_res[$pe]['url'].'" target="_new" title="'.str_replace("||","'",$emailall_res[$pe]['news_title']).'">'.str_replace("||","'",$emailall_res[$pe]['news_title']).'</a>
				</td></tr>';
		}

	$body .='<tr><td style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; font-weight: normal; color: #000000; text-decoration: none">Dear '.trim($user_name_).',<br>
					   &nbsp;&nbsp;The Latest newsitems are displayed below.<br><br></td></tr>';
	$body .=$table;				   
	$body .='<tr><td height="3">&nbsp;</td></tr><tr><td style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; font-weight: normal; color: #000000; text-decoration: none">
			  Regards,<br>
			  NewsManager Admin .<br><br>
			  <b><u>Note</u></b>:This is Auto generated mail thanks for not replying .<br></td></tr>';
	$body .='</table>';

	$sub="Latest News";
	$from ="From:NewsManager Admin \nContent-type:text/html";
	mail($user_mail_,$sub,$body,$from);
}
	$table='';
    $body='';
	$user_mail_='';
	$email_res[0]['selected_id']='';
	$email_qry='';
	$email_res='';
	$emailall_qry='';
	$emailall_res='';
	
} //For Loop users Closing

?>
Return current item: News Manager - RSS aggregator