Making a string from an array
Posted: Wed Dec 01, 2004 7:35 pm
Ok, I have a mutliple-select form where the user selects email addresses, and then it sends an email to all the addresses selected. How would I make the email send to all the selected users because it doesn't the way it is. Here is my code:
Here is the HTML/PHP that has the form:
Code: Select all
<?
$error = "";
mysql_connect("localhost","$username","$password") or die ("Unable to connect to MySQL server.");
$db = mysql_select_db("$database") or die ("Unable to select requested database.");
$number = mysql_query("select count(*) from test");
$numberpost = mysql_result($number, 0);
$numberpost1 = "$numberpost+4";
$email = mysql_query("SELECT email FROM teachers WHERE id='$_COOKIE[id]'");
while($row = mysql_fetch_array($email))
{
$email_result = $row['email'];
}
mysql_connect("localhost","$username","$password") or die ("Unable to connect to MySQL server.");
$db = mysql_select_db("$database") or die ("Unable to select requested database.");
IF($_POST[submit]){
IF($_POST[subject] == "" OR $_POST[emailbody] == ""){
$error = "<font color='#FFFFFF'><b>Sorry, but one of the forms was left blank.</b></font>";
}ELSEIF($_POST[subject] != "" AND $_POST[emailbody] != ""){
$error = "<font color='#FFFFFF'><b>Sent, $_POST[filter_teachers]</b></font>";
IF($_POST[filter_teachers] == "showall"){
$result = mysql_query("SELECT email FROM test") or die("Invalid query: " . mysql_error());
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
if(mail($line[email], $_POST[subject], $_POST[emailbody], "From: $email_result")){
}}}ELSEIF($_POST[filter_teachers] != "showall"){
mail($_POST[filter_teachers], $_POST[subject], $_POST[emailbody], "From: $email_result");
}}}
?>Code: Select all
<select multiple="multiple" size="6" name="filter_teachersї]">
<option value="showall">Choose a Teacher</option>
<option value="showall">----------------------</option>
<option value="showall">Send to All Teachers</option>
<option value="showall">----------------------</option>
<?
mysql_connect("localhost","$username","$password") or die ("Unable to connect to MySQL server.");
$db = mysql_select_db("$database") or die ("Unable to select requested database.");
$query="SELECT * FROM test ORDER BY id ASC";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
$i=0;
while ($i < $num) {
$teachers=mysql_result($result,$i,"id");
$teachersemail=mysql_result($result,$i,"email");
echo "
<option $selected value='$teachersemail'>$teachers</option>
";
$i++;
}
?>
</select>