I've written a mass email script that works fine. I have also created a table that will store letters that are sent out on a regular basis so you do not have to type the letters each time. The problem i am having is trying to display the letter in a textarea after the user has selected it. Here is my code, Please help on this
<?
$db_name = "email_letters";
$table_name = "letters";
$connection = @mysql_connect("localhost", "username", "password") or die ("couldn't connect");
$db = @mysql_select_db($db_name, $connection) or die ("Couldn't select database");
$sql = "SELECT
letter_body from $table_name where id = \"$id\"
";
$result = @($sql, $connection) or die ("Couldn't execute query");
while ($row = mysql_fetch_array($result)) {
$letter_body = $row['letter_body'];
}
$form_block = "
<FORM method = \"post\" action = \"$php_self\"
<h1> MIM MASS EMAILER</h1><br>
<p><strong>Your Name (as you would like it to appear on the emails): </strong></p>
<input type=\"text\" name=\"yourname\" size=30></p>
<p><strong>Your Email Address: (as you would like it to appear on the emails): </strong><br>
<input type=\"text\" name=\"youremail\" size=50></p>
<p><strong>Select an Email List: </strong></p><br>
<select name = \"emaillist\" multiple size =\"5\">
<option>All lists
<option>Contact list 1
<option>Contact list 2
<option>Contact list 3
<option>Employee list 1
<option>Employee list 2
<option>Employee list 3
<select>
<p><strong>Enter the subject (as you would like it to appear on the emails): </strong><br>
<input type=\"text\" name=\"subject1\" size=40></p>
//////////HERE IS THE PROBLEM PART (i think)////////////
<p><strong>Message body: </strong><br>
<textarea name="messagebody"><?= $letter_body ?> </textarea></p>
////////////////////////////////////////
<input type=\"hidden\" name=\"op\" value=\"ds\">
<p><input type=\"submit\" name=\"submit\" value=\"Start\"></p>
</form>
";
if ($op != "ds") {
echo "$form_block";
} else if ($op == "ds") {
if ($yourname == ""){
$name_err = "<font color = red>Please enter your name!</font><br>";
$send = "no";
}
// line 61
if ($youremail == ""){
$email_err = "<font color = red>Please enter an email address</font><br>";
$send = "no";
}
if ($emaillist == ""){
$list_err = "<font color = red>Please select a list from the options</font><br>";
$send = "no";
}
if ($subject1 == ""){
$subject1_err = "<font color = red>Please enter the subject of these emails</font><br>";
$send = "no";
}
if ($messagebody == ""){
$body_err = "<font color = red>Please enter the body of the email</font><br>";
$send = "no";
}
if ($send == "no") {
echo "$name_err";
echo "$email_err";
echo "$list_err";
echo "$subject1_err";
echo "$body_err";
echo "$form_block";
}
else if ($send != "no") {
// set up a message
$subject = "$subject1";
$msg = "$messagebody";
// connect to the database and collect addresses
$db_name = "brian_store";
$table_name = "auth_users";
$connection = @mysql_connect("localhost", "username", "password")
or die("Couldn't connect.");
// if statement will go here using $list so the correct database and table are selected
$db = mysql_select_db($db_name, $connection)
or die("Couldn't select database.");
$sql = "select emailaddress from auth_users";
$res = @($sql) or die("Couldn't get addresses.");
// loop through the result set and send mail
while ($email_row = @mysql_fetch_array($res)) {
// get the recipient address
$to = $email_row['emailaddress'];
// add the command here to get the recipients header
//send the mail
mail("$to", "$subject", "$msg", "$headers");
//print a confirmation to the screen
echo "mail sent to $to <br>";
}
}
}
?>
</body>