<?php
include "chkuser.php"; 
set_time_limit(0);
$site_main_path = "http://www.my-webprojects.com/intelliguardsecurity/";
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>News Letter</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="ssi.css" rel="stylesheet" type="text/css">
</head>

<body>

<?php
include "../conn.php";   
//$groupid = $_POST['groupname'];
$mail_subject = $_POST['subject'];
$mailtype = $_POST['mailtype'];

//if text type mail
if($mailtype == "text")
{
	$mail_body = $_POST['message'];
	$mail_body = $mail_body . "\n<a href='$site_main_path/unsubscribe.php' target='_blank'>To Unsubscribe click here</a>"; 
	$headers = "From: info@my-webprojects.com";
}
//HTML type mail
else
{
$contents = stripslashes($_POST['txtContent']);
$contents = $contents . "<br><br><a href='$site_main_path/unsubscribe.php' target='_blank'>To Unsubscribe click here</a>"; 

  $file = fopen("../newsletter_template/template.html",'rb');
  $data = fread($file,filesize("../newsletter_template/template.html"));
  fclose($file);
  $mail_body = str_replace("#mail_cont#",$contents,$data); 	

  

  $headers="MIME-Verson:1.0\n";
  $headers = $headers . "Content-Type: text/html;charset=iso-8859-1\n";
  $headers = $headers . "From: info@intelliguardsecurity.com";


  
}

//send mails
$sqld = "SELECT * FROM subscribedusers ";
$resultd = mysql_query($sqld,$eclipse); 
$i = 0;
	while($rowd = mysql_fetch_object($resultd))
	{
		$mail_to = $rowd->email;
		mail($mail_to,$mail_subject,$mail_body,$headers);
		$i = $i + 1;
	}
?>
<p align="center" class="normalBoldTxt"><?php echo $i; ?> Mails Sent...</p>

</body>
</html>
