<HTML><BODY onload="document.MyForm.Password.focus()">

<?php

 echo <<< Begin
        <center>
        <H2 align="center">Sending Email</H2>
        </center>
        <p>
        <CENTER>
        <FORM ACTION="{$_SERVER['PHP_SELF']}" NAME="MyForm" METHOD="POST">
        <CENTER>
	  <B>Username:</B> <input name="Username" size="30">

        <B>Password:</B> <input name="Password" type="password" size="10">

	<TABLE BGCOLOR=lightgrey BORDER=1 BORDERCOLOR=gray>
        	<TR>
        	<TD>
        	<B>To:</B></TD>
        	<TD>
        	<TABLE>
        	<TR>
        	<TD>
        	<INPUT NAME="C1" TYPE="checkbox" VALUE="C1">List 1
        	</TD>
        	<TD>
        	<INPUT NAME="C2" TYPE="checkbox" VALUE="C2">List 2
        	</TD>

        	</TR>
        	</TABLE>
        	</TD>
        	</TR>

        	<TR>
        	<TD><B>Cc:</B></TD>
        	<TD><INPUT NAME="Cc" SIZE=50></TD>
       	 </TR>
	
	 	<TR>
        	<TD><B>From:</B></TD>
        	<TD><INPUT NAME="From" SIZE=50></TD>
        	</TR>

        	<TR>
        	<TD><B>Your Email:</B></TD>
        	<TD><INPUT NAME="Email" SIZE=50></TD>
        	</TR>

        	<TR>
       	 <TD><B>Subject:</B></TD>
        	<TD><INPUT NAME="Subject" SIZE=50></TD>
       	 </TR>

        	<TR>
        	<TD><B>Message:</STRONG></TD>
        	<TD>
        	<TEXTAREA NAME="Message" ROWS=16 COLS=75 WRAP="virtual"></TEXTAREA>
        	</TD>
       	 </TR>

       	 <input name='submitted' value='TRUE' type='hidden'>
       	 </TABLE>

        	<TABLE BGCOLOR=lightgrey BORDER=1 BORDERCOLOR=gray>
        	<TR>
        	<TD><INPUT TYPE="submit" VALUE="SEND">
       	 </TD>
       	 <TD>
       	 <INPUT TYPE="reset" VALUE="RESET">
        	</TD>
        	</TR>
       	 </TABLE>
Begin;

if (isset($_POST['submitted']))
{
	$errors = array();
	$username = trim(stripslashes($_POST['Username']));
	$password = trim(stripslashes($_POST['Password']));
    	$from = trim(stripslashes($_POST['From']));
      $email = trim(stripslashes($_POST['Email']));
	if (empty($username))
		$errors[] = "You have to enter a username.";
	if (empty($password))
		$errors[] = "You have to enter a password.";	
	if (empty($email))
		$errors[] = "You have to enter your email address.";
	if (!isset($_POST['C1']) && (!isset($_POST['C2'])))
	{
		$errors[]= "You have to choose an email list.<BR>\n";
	}
	if (!empty($errors))
	{
		echo "<h1 align=center>ERROR</h1><center>\n";
		foreach ($errors as $e)
			echo $e, "<P>\n";
		echo "</center>\n";
	}
	else
	{
		@$d = mysql_connect('localhost','database_username','database_password') or  die("Can't connect");
		@mysql_select_db('email') or die();

		$q = "select count(*) from users where username='$username' and password=sha1('$password')";
		$r = @mysql_query($q) or exit();
	
		$row = mysql_fetch_row($r);
		$k = $row[0];
		mysql_close($d); 
		if($k > 0)
		{
			if (isset($_POST['C1']))
			{
				@$d = mysql_connect('localhost','database_username','database_password') 
					or die("Can't connect");
				$s = mysql_select_db('email');
				if (!$s)
					echo "Can't open DB.<BR>";

				$q = "select list1 from lists where list1 is not null";
				$r = @mysql_query($q);
				if (!$r)
					echo "Query Failed<BR>";
				else
				{
					$n = mysql_num_rows($r);
					while ($row = mysql_fetch_row($r))
					{
						$s  = $row[0];
						if (!empty($s))
				   		 {
							$cc = trim($_POST['Cc']);
                					$subject = stripslashes(trim($_POST['Subject']));
                					$body = stripslashes(trim($_POST['Message']));
                					$headers = "From: $from <$email>\r\n";
	            				$to = $s;
							if (!empty($cc))
	        	    					$headers .= "CC: $cc\r\n";
	        	    				mail($to,$subject,$body, $headers);
        	       				echo "<P align=center>Your email has been sent to $to<BR>\n";
						}
					}
					mysql_close($d); 
				}
			}
			
			if (isset($_POST['C2']))
			{
				@$d = mysql_connect('localhost','database_username','database_password') 
					or die("Can't connect");
				$s = mysql_select_db('email');
				if (!$s)
					echo "Can't open DB.<BR>";

				$q = "select list2 from lists where list2 is not null";
				$r = @mysql_query($q);
				if (!$r)
					echo "Query Failed<BR>";
				else
				{
					$n = mysql_num_rows($r);
					while ($row = mysql_fetch_row($r))
					{
						$s  = $row[0];
						if (!empty($s))
				   		 {
							$cc = trim($_POST['Cc']);
                					$subject = stripslashes(trim($_POST['Subject']));
                					$body = stripslashes(trim($_POST['Message']));
                					$headers = "From: $from <$email>\r\n";
	            				$to = $s;
							if (!empty($cc))
	        	    					$headers .= "CC: $cc\r\n";
	        	    				mail($to,$subject,$body, $headers);
        	       				echo "<P align=center>Your email has been sent to $to<BR>\n";	
						}
					}
					mysql_close($d); 
				}
			}
					
		
		} // $k > 0
		else
			echo "<P align=center>Wrong Password<P>\n";			
        }// else (empty errors)
    
} // if (form submitted)
?>
</BODY></HTML>

