Page 1 of 1

mail function, mail body and send to

Posted: Sun Jul 06, 2003 5:07 pm
by matthewod
Hi all
I am working on putting together a newsletter program and I am having a few difficulties. Here is the situation: the site administrator (admin) creates the newsletter (subject, body), the message is stored in the database for archive and to modify before sending, next page the admin selects who they want to send the message to. Within the same functions I have to select the message number and output it as the body of the mail. What I am getting is the message is sent to the proper receipents, but there is no body or subject.
Is there some sort of way to merge the output of who (receipents) with what (subject, body) and send the newsletter?

Here is the code:
<?
session_start();

include("");
$connection =@mysql_connect($host_name, $user_name, $pass_word) or die(mysql_error());

$db = @mysql_select_db($db_name, $connection) or die(mysql_error());
$mysql = "SELECT * FROM table WHERE message_number = '$number' ";

$result = @mysql_query($mysql, $connection) or die(mysql_error());
if (mysql_num_rows($result) >0 ) {
while ($row = mysql_fetch_array($result)) {
$date_added =$row['date_added'];
$subject =$row['subject'];
$heading_1 =$row['heading_1'];
$heading_2 =$row['heading_2'];
$para_1 =$row['para_1'];
$para_2=$row['para_2'];
$para_3=$row['para_3'];
$message_number =$row['message_number'];

$body="<html>
<head>
<title>$heading_1</title>
<style type=\"text/css\">
</style>
</head>
<body>
<table width=\"780\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
<tr>
<td height=\"139\" background=\"top_banner_left.jpg\">&nbsp;</td>
<td height=\"139\" valign=\"middle\" background=\"top_banner_center.jpg\">
<table width=\"100%%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
<tr>
<td width=\"21%%\">&nbsp;</td>
<td width=\"79%%\" align=\"left\" valign=\"top\"> <h2><font color=\"#FFFFFF\">$heading_1<br>
<font size=\"2\">$heading_2</font></font></h2></td>
</tr>
</table></td>
<td height=\"139\" background=\"/top_banner_right.jpg\">&nbsp;</td>
</tr>
<tr>
<td width=\"150\" height=\"30\"><font size=\"2\">&nbsp;</font></td>
<td width=\"580\" height=\"30\"><font size=\"2\">$subject</font></td>
<td width=\"50\" height=\"30\">&nbsp;</td>
</tr>
<tr>
<td height=\"30\" align=\"right\"><font size=\"2\">&nbsp;</font></td>
<td height=\"30\"><font size=\"2\">To:$fname $lname</font></td>
<td height=\"30\">&nbsp;</td>
</tr>
<tr>
<td width=\"150\" align=\"right\">&nbsp;</td>
<td width=\"580\" align=\"left\" valign=\"top\"> <p>$para_1</p>
<p>$para_2</p>
<p>$para_3</p></td>
<td width=\"50\">&nbsp;</td>
</tr>
<tr>
<td width=\"150\">&nbsp;</td>
<td width=\"580\"> <font size=\"2\">Login to the </font></td>
<td width=\"50\">&nbsp;</td>
</tr>
</table>
</body></html>";

}
}

require("");

$connection =@mysql_connect($host_name, $user_name, $pass_word) or die(mysql_error());
$db = @mysql_select_db($db_name, $connection) or die(mysql_error());


$sql="SELECT DISTINCT * FROM table GROUP BY state";
$result = @mysql_query($sql, $connection) or die(mysql_error());

while ($row = mysql_fetch_array($result)) {
$state=$row['state'];
$state_block .="<option value=\"$state\">$state</option>";
}

$sql="SELECT DISTINCT * FROM table GROUP BY city";
$result = @mysql_query($sql, $connection) or die(mysql_error());

while ($row = mysql_fetch_array($result)) {
$city=$row['city'];
$city_block .="<option value=\"$city\">$city</option>";
}

require("");

$connection =@mysql_connect($host_name, $user_name, $pass_word) or die(mysql_error());
$db = @mysql_select_db($db_name, $connection) or die(mysql_error());

$sql = "SELECT * FROM type_table";

$result = @mysql_query($sql, $connection) or die(mysql_error());
if (mysql_num_rows($result) >0 ) {
while ($row = mysql_fetch_array($result)) {
$seminar_type = $row[type'];
$seminar_name =$row[name'];
$type_block .="<option value=\"$seminar_type\">$seminar_name</option>";
}
}



$form_block="<table width=\"100%%\" cellspacing=\"0\" cellpadding=\"0\">
<tr>
<td colspan=\"2\"><p>Send Newsletter to:</p>
<p>&nbsp;</p></td>
</tr>
<tr>
<td width=\"50%%\" valign=\"middle\" >Send All</td>
<td width=\"50%%\" valign=\"middle\" >
<form method=\"post\" action=\"$_SERVER[PHP_SELF]\">
<input type=\"hidden\" name=\"user_id\" value=\"$user_id\">
<input type=\"hidden\" name=\"message_number\" value=\"$number\">
<input type=\"hidden\" name=\"op\" value=\"ds\">
<input type=\"submit\" name=\"Submit\" value=\"Go!\"></form></td>
</tr>
<tr>
<td width=\"50%%\">State:</td>
<td width=\"50%%\"><form method=\"post\" action=\"$_SERVER[PHP_SELF]\">
<select name=\"state\"><option >Select State</option>
$state_block
</select>
<input type=\"hidden\" name=\"user_id\" value=\"$user_id\">
<input type=\"hidden\" name=\"send_by\" value=\"state\">
<input type=\"hidden\" name=\"message_number\" value=\"$number\">
<input type=\"hidden\" name=\"op\" value=\"ds\">
<input type=\"submit\" name=\"Submit\" value=\"Go!\"></form></td>
</tr>
<tr>
<td>Or City:</td>
<td><form method=\"post\" action=\"$_SERVER[PHP_SELF]\"><select name=\"city\">
<option >Select City</option>
$city_block</select>
<input type=\"hidden\" name=\"user_id\" value=\"$user_id\">
<input type=\"hidden\" name=\"send_by\" value=\"city\">
<input type=\"hidden\" name=\"message_number\" value=\"$number\">
<input type=\"hidden\" name=\"op\" value=\"ds\">
<input type=\"submit\" name=\"Submit2\" value=\"Go!\"></form></td>
</tr>
<tr>
<td>Or Seminar Type</td>
<td><form method=\"post\" action=\"$_SERVER[PHP_SELF]\"><select name=\"type\">
<option >Select Type</option>
$type_block
</select>
<input type=\"hidden\" name=\"send_by\" value=\"type\">
<input type=\"hidden\" name=\"user_id\" value=\"$user_id\">
<input type=\"hidden\" name=\"message_number\" value=\"$number\">
<input type=\"hidden\" name=\"op\" value=\"ds\">
<input type=\"submit\" name=\"Submit4\" value=\"Go!\"></form></td>
</tr>
</table>";

?>
<html>
<head>
<title>ESA Admin Pages</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="pragma" content="no-cache">

<style>
<!--
body {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12pt;
text-decoration: none;
margin:0px;
}
-->
</style>
</head>

<body >...
<?
if (session_is_registered("valid_user"))
{
include("admin_menu.php");
echo"</font></td>
<td width=\"40%%\" valign=\"top\">";
if ($_POST[op] !="ds") {
echo "$form_block";

} else if ($_POST[op] == "ds") {


if($send_by=="id") {
$sql = "SELECT * FROM table WHERE id = '$id' ";
}
if($send_by == "all") {
$sql = "SELECT fname, lname, email FROM table";
}

if($send_by =="state") {
$sql ="SELECT * FROM table WHERE state = '$state' ";
}

if($send_by =="city") {
$sql ="SELECT * FROM table WHERE city = '$city' ";
}

if($send_by =="type") {
$sql = "SELECT * FROM table WHERE type_1 = '$type' and


}

require ("");
$connection =@mysql_connect($host_name, $user_name, $pass_word) or die(mysql_error());

$db = @mysql_select_db($db_name, $connection) or die(mysql_error());
$result_2 = @mysql_query($sql, $connection) or die(mysql_error());

if (mysql_num_rows($result_2) >0 ) {
while ($row = mysql_fetch_array($result_2)) {
$licensee_id=$row['licensee_id'];
$fname=$row['fname'];
$lname=$row['lname'];
$email=$row['email'];
}
}
$subject=$message_subject;
$headers ="From: Company Admin<email@domainname.com\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";


mail("$email", "$subject", "$body", "$headers");

echo "Newsletter sent to:";
echo "$fname $lname<br>";


echo "<p><a href=\"admin_login_main.php?user_id=$user_id\">Return to Main Admin Page</a></p>";
}
}
else
{
echo "<p> You are not logged in.</p>";
echo "<p>You must log in to use the Admin Area!</p>";
include("login_form.php");
}
?>
</td>
<td width="200">&nbsp;</td>
</tr>
<tr bgcolor="#FFFFFF">
<td height="100" align="left" valign="top" bgcolor="#32ACA8"><img src="images/p102.jpg" width="200" height="40"></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>

</body>
</html>

END code

Obviously there has been some stuff deleted for security reasons. But you the idea of what I am trying to do.

Any thoughts would help...

Thanks
MDell