<?php
//prevents caching
header("Expires: Sat, 01 Jan 2000 00:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: post-check=0, pre-check=0",false);
session_cache_limiter();
session_start();

//require config and functions files
require('../config.php');
require('../functions.php');

//check for administrative rights
if (allow_access(Administrators) != "yes")
{
	include ('../check_login.php');
	exit;
}

//make the connection to the database
$connection = @mysql_connect($server, $dbusername, $dbpassword) or die(mysql_error());
$db = @mysql_select_db($db_name,$connection)or die(mysql_error());

//make the dbase query selecting only email address
$sql ="SELECT * FROM $table_name";
$result = @mysql_query($sql,$connection) or die(mysql_error());
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Language" content="es-ES" />
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>Enviar e-mail masivo a todos los cliente - La Factoría Verde</title>
  <link rel="stylesheet" type="text/css" href="adminpage.css">
  <link rel="stylesheet" type="text/css" href="estilos.css">
</head>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<body>
    <div id="layout">
        <div id="header">
            <img src="../img/lafactoriaverde.gif" alt="La Factoría Verde" />
            <?php 
            	$menu_activo='mail_masivo';
            	include('_menu.php'); 
            ?>	
        </div>
        <div id="content">
                <h1>E-mail masivo</h1>
<p>Tu mensaje está siendo enviado a los siguientes usuarios:</p>
<ul>

<?php
	while ($sql = mysql_fetch_object($result)) 
	{
	    $e_addr = $sql -> email;
		$e_user = $sql -> username;
		$subject = $_POST[e_subject];
		$mailheaders = $_POST[e_message]; 
		mail($e_addr, $subject, $mailheaders, "From: $_POST[$e_from] <$adminemail>\n");
		echo "<li>$e_user</li>";
	}
	echo "</ul>"
?>
        </div>
        <div id="footer">
        </div>
    </div>
</body>
</html>
