0

Hi,

I am developing a simple application mailing system in which i need to place a check box in a listbox,which having emails id from database. How do i do it?...For example in the mailing system application , when i have to send a email, it displays all the emails as a list with checkbox where in i can select any emails from the list or the options i choose select All.here is my code.......

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Send e-mails</title>

<?php
$from = "mail@mail.com";

$mesa = $_POST['mess'];
$subje = $_POST['subj'];
$mails = $_POST['mail'];



?>

<link rel="stylesheet" href="stylesheet.css"> <!-- Main Stylesheet -->

</head>

<body style="margin: 1px; font-family: arial, verdana, san-serif; font-size: 14px;">
<table width="80%" border="1" align="center">
<tr>
<td><div align="right">
Add new e-mail <a href="index1.php"><font color=#005aee>Here</font></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='logout.php'>Logout</a></div>
</td>
</tr>

<tr>
<td>

<table>
<tr>
<td>

<table>
<tr>
<td>

<form name=mailids>
<select name=test multiple size=26 style="width: 200px;">

<?php

include("connect.php");
        $query="SELECT email FROM emails ORDER BY email";
        $rs = mysql_query($query);

        while($row = mysql_fetch_array($rs))
            {

            echo"<option>".$row['email']."</option>";//here i need option checkboxes along with emails 
            }

?>


</select>
</form>

</td>
</tr>
</table>
</td>

<!-- To add required code to make the milids selected after sending mail -->
<!--script language=javascript>
document.mailids.test[0].selected = true;
</script-->

<td>
<table>
<tr>
<td>
<form name=message method=post action="<?php $PHP_SELF?>">
<br>
FROM :<br>
 <input name=from value=<?php echo "$from";?> type=text size=59 readonly>
<br><br>
Subject:<br>
<input name=subj value="<?php echo($subje); ?>" type=text size=59><br><br>
Message:<br>
<textarea name="mess"  rows=16 cols=50 wrap=physical><?php echo($mesa); ?></textarea>
<input type=hidden name=mail>
<br><br>

<br><br>
<input type=submit value="Send Mail" onClick="submitForm()">
</form>

<script language=javascript>
function submitForm()
{
var subject = document.message.subj.value;

if(subject.length == "")
{
alert("Please give a proper subject");
return false;
}

var message = document.message.mess.value;

if(message.length == "")
{
alert("Please give a proper message");
return false;
}


var tot = document.mailids.test.length;
var maildis = "";
for(i=0; i<tot; i++)
{
    if(document.mailids.test[i].selected == true)
    {
        var ssr = document.mailids.test[i].value;
        maildis = maildis+"||"+ssr;
        document.message.mail.value = maildis;
    }
}

var maaa = document.message.mail.value;
echo(maaa);
document.message.submit();
}
</script>

</td>
</tr>
</table>
</td>

</tr>
</table>

</td>
</tr>

</table>
<table align="center">
<tr>
<td>

<?php
$tok = strtok($mails, " ||");
echo("Mail sent to:");


$message1 = str_replace("<br />", "\n", $mesa);
$message1 = str_replace("\\\\","",$message1);
$message1 = str_replace("\'","'",$message1);
$message1 = str_replace("\\\"","\"",$message1);
$message1 = nl2br($message1);

while ($tok)
{
    /* additional headers */
    /* To send HTML mail, you can set the Content-type header. */

    $headers1  = "MIME-Version: 1.0\r\n";
    $headers1 .= "Content-type: text/html; charset=iso-8859-1\r\n";
    $headers1 .= "To: ".$tok."\r\n";
    $headers1 .= "From: ".$from."\r\n";
    $headers1 .= "Reply-To: ".$from."\r\n";
    $headers1 .= "Cc: \r\n";

    echo("<font color=green> $tok </font>");
    if(@mail($tok,$subje,$message1,$headers1))
    {
        echo("-<font color=#005aee> Mail Sent Successfully </font>,");
    }
    else
    {
        echo("-<font color=red>Mail Not Sent </font>,");
    }
    $tok = strtok("||");
}
?>
</td>
</tr>
</table>


</body>
</html>

Edited by mike_2000_17: Fixed formatting

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by madCoder
0

You can't combine checkboxes within a select list. HTML just doesn't work that way. However, the effect would be the same a MULTIPLE selection box. See HTML <select> multiple Attribute for details.

This will let a user Ctrl-click (or Cmd-click on Mac) multiple choices from a select list.

Since you may get multiple results back, name the field with '[]' at the end. PHP will treat the posted data for that field as an array automatically.

<select name="emails[]" multiple="multiple" size="2">
 <option value="abc@def.com">John Doe</option>
 ...
</select>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.