<?php	

    require_once('include/config.php');
    require_once('include/startup.php');
	
	ini_set("memory_limit","53554432");
	ignore_user_abort(true);
	set_time_limit (0);     
	
	$alltables = new AllTables();
	$mailsending    = new Mailsending();
    
    $emailssend = $_REQUEST['emailto'];
	$emailsTo = str_replace(';',',',$emailssend);
	$emailsToSend = explode(',',$emailsTo);
	$rowcount = count($emailsToSend);
    
    date_default_timezone_set('Asia/Kolkata');
	
	if (is_array($emailsToSend))
	{
	    $form_message = stripcslashes(urldecode($_REQUEST['emailmessage']));

		$NewProduct['subject']= sanitize($_REQUEST['emailsubject'],SQL); 
		$NewProduct['emailmessage']= sanitize($_REQUEST['emailmessage'],SQL);
        $NewProduct['fromemailid']= FROM_EMAIL;
        $NewProduct['user_exhibitorid']= $G_userid;      
        $NewProduct['date_of_mail']= date("Y-m-d H:i:s");
		
        $gallery = $mailsending -> addMailsending($NewProduct,"exhibitor_maillogheader");
		
		$mailheaderid = $gallery; //$mailheaderdata[0]['mailheaderid'];
        
        date_default_timezone_set('Asia/Kolkata');
		for ($i=0;$i<$rowcount;$i++)
		{
			$percent = "'".intval(($i+1)/$rowcount * 100)."%'";
			$toEmails = filter_var($emailsToSend[$i],FILTER_VALIDATE_EMAIL);
			$NewEMAIL['headerid']= $mailheaderid;
			$NewEMAIL['toemail']= $toEmails;
			$NewEMAIL['send_date'] = date("Y-m-d H:i:s");
			
			if ($toEmails >'')
			{
				$addsendemail = $mailsending -> addMailsending($NewEMAIL,"exhibitor_maillogdetail");
				$detailid = $addsendemail; //$maildetaildata[0]['detailid'];

				$imgname = $detailid.'-blink.gif';
				$giffile ="https://newexhibition.polymertubing.in/images/$imgname";
				$resultstr ='<img src="'.$giffile.'" width="1px" height="1px">';
				$html_message = $form_message.$resultstr;
            }
			$uploadPath = '../images_temp/pdf/';
    		$to_name = $toEmails;
    		$from_name = 'Testing Exhibition';
    		$from_email = FROM_EMAIL;
		    $subject = $_REQUEST['emailsubject'];
	        $text_message = '';
		    $to_email = $toEmails;
		    
    		if ($to_email > '')
    		{
                $mailsent = sendPHPMail($from_name, $from_email, $to_name, $to_email, $subject, $text_message, $html_message); 
		    }
		}

		if($mailsent == '')
		{
		    $redirect_url = DOC_ROOT;      
    		echo"<script> alert('Mail Send Successfully...');setTimeout(function() { window.location = '$redirect_url'; } ); </script>";
    	    exit();
		}
		else
		{
		    $redirect_url = DOC_ROOT;
    		echo"<script> alert('Error Occur While Sending Mail.');setTimeout(function() { window.location = '$redirect_url'; } ); </script>";
    	    exit();
		}
	} 
?>