<?php
include("config.php");
mysql_connect($db_host, $db_user, $db_pwd);
mysql_select_db($db_name);
if (!$_POST) {
include("form.php");
} else {
$formbody = $_POST['formbody'];
$sql = "SELECT $db_usernamefield, $db_emailfield FROM $db_table";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)){
$username = $row['username'];
$email = $row['email'];
$body = "$formbody";
$body = str_replace("[username]", $username, $body);
mail($email, $emailsubject, $body, "From: $fromname <$fromemail>");
if(mail ($email, $emailsubject, $body, "From: $fromname <$fromemail>"))
echo "Messages sent";
}
}
?>