Location: PHPKode > scripts > FreeCast > broadcast.php
<?php
##### Variables to be changed by the user #####
$host="localhost";
$user="root";
$pass="pass";
$dbase="freecast";
$userstable="users";
$emailfield="email";
$namefield="name";
$sender="hide@address.com";
$globalpass="globalpass";
##### End of variables to be changed by the user #####

mysql_connect($host,$user,$pass);
mysql_select_db($dbase);


if($_POST[ok])
{
	if($_POST[pass]!=$globalpass) die("Wrong pass!");
	
	//select users
	$q="SELECT * FROM $userstable ORDER BY uid";
	$res=mysql_query($q) or die(mysql_error());
	
	$from=$_POST[sender];
	$subject=$_POST[subject];
	$cnt=0;
	
	$sql="INSERT IGNORE INTO freecast_smails (sender, receiver, subject, message)
			VALUES ";
	
	while($member=mysql_fetch_array($res))
	{
		$cnt++;
		$message=str_replace("%NAME%",$member[$namefield],$_POST[message]);
		$message=nl2br($message);
		
		if($member[$emailfield])
		{
			$message.="<br><br><br>---------<br>
			You receive this message because you are a member in hywd.info.
			To stop receiving messages, please log in and delete your account
			or reply to this email";			
			
			$sql.=" ('$sender',\"".$member[$emailfield]."\",
			\"$subject\",\"".mysql_real_escape_string($message)."\"), ";			
		}
	}
	
	
	$sql=substr($sql,0,strlen($sql)-2);
	mysql_query($sql) or die(mysql_error());
	
	echo "Broadcast scheduled for $cnt members";
}

?>

<form method=post>
<table align=center>
<tr><td>Pass:</td>
<td><input type=text name=pass size=30></td></tr>
<tr><td>Subject:</td>
<td><input type=text name=subject size=30></td></tr>
<tr><td colspan=2>Message:
<textarea name=message rows=10 cols=60></textaea></td></tr>
<tr><td colspan=2><input type=submit name=ok value="Send"></td></tr>
</table>
</form>
Return current item: FreeCast