Hello Everybody

In Php iam using the checkbox and it has been one month i can not solve it; when i select one checkbox from several ones , and i click send e-mail= it is sending to all e-mails; it is not sending to the selected checkbox ; I need guys help with it pls,if you guy s need more info let me know and check attached files thks
regards

Attachments
<?php ob_start() ?>
<?php

require("class.phpmailer.php");

session_start();

//Check to see if the user was already logged on
if ($_SESSION["login"] !=1)
{
header ('Location: index.php?Msg=3');

}
//echo $_SESSION["login"];


$PromoFont = "";
$PromoFontSize = "";
$PromoFooter = "";
$PromoFromName = "";
$PromoFromAddress = "";
$PromoFontColor = "";
$msg_error="";
$PromoPWD="";
$Promotion_ID=0;

//Connect to DB
$dbcnx = mysql_connect('host', 'database', 'password');

if (!$dbcnx) {
	echo '<Font color=red> Could not connect to the database at this time, please try later';
	exit();
}

//Select the DB we want to deal with
mysql_select_db ("database");

	$query = "SELECT * FROM ApplicationSettings";
        $result=mysql_query($query);
	$num=mysql_numrows($result);

	if($num!=0)
	{
		$PromoFont = mysql_result($result,0,"PromoFont");
		$PromoFontSize = mysql_result($result,0,"PromoFontSize");
		$PromoFooter = mysql_result($result,0,"PromoFooter");
		$PromoFooter = preg_replace("((\')+)", ' ',$PromoFooter);
		$PromoFooter = "<a href=mailto:support@.com>";
		$PromoFromName = mysql_result($result,0,"PromoFromName");
		$PromoFromAddress = mysql_result($result,0,"PromoFromAddress");
		$PromoFontColor = mysql_result($result,0,"PromoFontColor");
		$PromoPWD = mysql_result($result,0,"PromoPWD");

	}

if(isset($_REQUEST['hidaction']))
{
	if($_REQUEST['hidaction']=="send")
	{


	$Body = $_REQUEST['PromoEmail'];
	$Body = preg_replace("((\\\)(\")+)", "\"",$Body);
	$Body = preg_replace("((\\\)(\')+)", '\'',$Body);
	$Body = preg_replace("((\\\)(\\\)+)", "\\",$Body);
	$Body = preg_replace("((<P><br>)+)", "<br>",$Body);
	$Body = preg_replace("((<P><BR>)+)", "<br>",$Body);
	$Body = preg_replace("((<P>)+)", "<br>",$Body);
	$Body = preg_replace("((</P>)+)", "",$Body);
	//echo $Body;
	//exit();

	$To=$_REQUEST['To'];
	$Users=$_REQUEST['users'];

	//Get all mailing list users
	$Promotion_ID = $_REQUEST['Promotion_ID'];
	if ($To=="G")
	{
		if($Promotion_ID==0)
		$query="Select * from promotion WHERE $Promotion_ID= Email order by Email ";
        else
        $query="Select * from promotion WHERE $Promotion_ID= Promotion_ID order by Email ";
	}
	if($To=="U")
	{
		$query="Select * from promotion  WHERE $users order by FName,LName";
	}
	//echo $query;
	//exit();

	$result = mysql_query($query);

	$mail = new PHPMailer();
    $mail->Host = "relay-hosting.secureserver.net";
    $mail->SMTPAuth  = true;
    $mail->Username  = $PromoFromAddress;
	$mail->From = $PromoFromAddress;
    $mail->Password  =  $PromoPWD;
    $mail->Mailer = "smtp";
	$mail->IsSMTP(); // telling the class to use SMTP
	$mail->FromName = $PromoFromName;
	$mail->IsHTML(true);
	$mail->AddReplyTo('support@.net', 'Support Department');

	//Loop thru all data in the recordset
	while ($row = mysql_fetch_array($result))
		{

		$mail->AddAddress($row['Email']);
		//echo $row['Email'];
		//exit();
		$mail->Subject = $_REQUEST['txtsubject'];

		if ($row['Sex']==0)
		{
			$mail->Body = "<Font face=\"$PromoFont\" color=$PromoFontColor size=$PromoFontSize>Dear Ms. " . $row['LName'] . " " . $row['FName'] . ",  " . $Body;
		}
		if($row['Sex']==1)
		{
			$mail->Body = "<Font face=\"$PromoFont\" color=$PromoFontColor size=$PromoFontSize>Dear Mr. " . $row['LName'] . " " . $row['FName'] . ",  " . $Body;
		}
		if($row['Sex']==2)
		{
			$mail->Body = "<Font face=\"$PromoFont\" color=$PromoFontColor size=$PromoFontSize>Dear  " . $row['LName'] . " " . $row['FName'] . ",  " . $Body;
		}

		if($row['LName']=="" && $row['FName']=="")
		{
			$mail->Body = "<Font face=\"$PromoFont\" color=$PromoFontColor size=$PromoFontSize>Dear Sir, <br> " . $Body;

		}
		if($_REQUEST['hidattch']!=""){
			$hidattach=$_REQUEST['hidattch'];
			$mail->AddAttachment("uploads/$hidattach", "$hidattach");

		}
        $m=$row['Email'];
		if(!$mail->Send())
		{
			$msg = " $msg <br> <font color=red>Mailer Error:  $mail->ErrorInfo - Email Address:$m</font>";

		}
		else
		{
			$msg="$msg <br> <font color=green>Message Sent To : $m</font>";
		}


		$mail->ClearAddresses();
  		$mail->ClearAttachments();
		}

	}
	//mysql_close();

	if ($msg=="")
		$msg_error="<font color=green>Message sent to zero recipient!</font>";

}
?>
<?php ob_end_flush() ?>
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">

<title>
 Admin Page</title>
<script language="JavaScript" type="text/javascript" src="richtext.js"></script>
<script language=javascript>

function fctcancel()
{
	location.replace("http://www.net/admin/main.php");
	return;

}
function SaveSettings()
{
	//Validation
	if(document.frm.To[1].checked && document.frm.users.value=="")
	{
		alert("Please specify users that you want to send the newsletter to");
		return;
	}

	//alert(escape(document.frm.PromoEmail.value));
	updateRTE('PromoEmail');
	document.frm.submit();
}
function attach()
{
window.open ("http://www.net/admin/uploader.php","uploader","menubar=0,resizable=0,width=450,height=220");
}
function check()
{

	if(document.frm.To[1].checked)
	{
	document.frm.btnselect.disabled=false;
	document.frm.PromoGroupID.disabled=true;
	}
	else
	{
	document.frm.btnselect.disabled=true;
	document.frm.PromoGroupID.disabled=false;
	}
}
function openchoice()
{
window.open ("http://www.net/admin/selectusers.php","uploader","menubar=0,resizable=1,scrollbars=1,width=800,height=500");
}
</script>
</head>
<body>

<table border="2" cellpadding="8" cellspacing="0" style="border-collapse: collapse" bordercolor="#808080" width="95%" bgcolor="#FFFFFF">
  <tr>
    <td width="100%" bgcolor="#DAF1DB">
	<table width=100%>
	<tr>
	<td align=left>
	<b><font face="Verdana">Selecting One E-mail </font></b>
        </td>
	<td align=right><b><font face="Verdana"><a href="main.php">Home</a> &nbsp;&nbsp; <a href=index.php>Logout</a></font></b>
        </td>
	</tr>
        </table>


  </tr>
  <tr>
    <td>
    <br>
    <table border="2" cellpadding="4" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="95%">
      <tr>
        <td width="100%">
	<?php
	if ($msg_error!="")
	echo "Message was not sent to the following emails:<br>";
	echo $msg_error;
	?>
	<form name=frm action=selection.php method=post>
	<input type=hidden name=hidaction value=send>
	<script language=javascript>
		initRTE("images/", "", "");
	</script>
	<table width=100%>
	<tr>
		<td>
			<font face=verdana size=2>From:</font>
		</td>
		<td>
			<font color=gray face=verdana size=2><?php echo "$PromoFromName < $PromoFromAddress>"; ?>
		</td>
	</tr>
	<tr>
		<td>
			<font face=verdana size=2><INPUT TYPE=RADIO NAME="To" VALUE="G" onclick="check()" checked>To Group:</font>
		</td>
		<td>

				<select name=Promotion_ID >
				<option value=0 selected>All</option>
				<?php

				//Get all mailing list users
				$sql="Select * from promotion WHERE Promotion_ID order by Email ";
				//echo $sql;
				//exit();

				$result = mysql_query($sql);

				//Loop thru all data in the recordset
				while ($row = mysql_fetch_array($result)) {
				echo "<option value=";
				echo $row['Promotion_ID'];
				if ($row['Promotion_ID']==$Promotion_ID) echo " selected ";
				echo  ">";
				echo $row['Email'];
				echo "</option>";
				}

				?>
				</select>
		</td>
	</tr>
	<tr>
	<td><font face=verdana size=2><INPUT TYPE=RADIO NAME="To" VALUE="U" onclick="check()">To Users:</font></td>
	<td><input name=btnselect type=button value="..." onclick="openchoice()" disabled><input type=hidden name=users value=""></td>
	</tr>
	<tr>
		<td>
			<font face=verdana size=2>Subject:</font>
		</td>
		<td>
			<input type=text name=txtsubject size=80>
		</td>
	</tr>
	<tr>
		<td>
			<font face=verdana size=2>Attachment:</font>
		</td>
		<td>
			<input type=button value="Add Attachment" onclick=attach()>
			<input type=hidden name=hidattch>
		</td>
	</tr>
	<tr>
		<td valign=top>
			<font face=verdana size=2>Email:</font>
		</td>
		<td>
			<script language="JavaScript" type="text/javascript">
			<!--
			//Usage: writeRichText(fieldname, html, width, height, buttons, readOnly)
			writeRichText('PromoEmail', '<font face="<?php echo $PromoFont;?>" color=<?php echo $PromoFontColor;?> size=<?php echo $PromoFontSize;?>><br><br><?php echo preg_replace("((\r\n)+)", '', $PromoFooter); ?>', 200, 200, true, false);
			//-->
			</script>
		</td>
	</tr>
	<tr>
		<td align=right>

		</td>
		<td align=right>
			<input type=button value="   Send   " onclick="SaveSettings()">&nbsp;&nbsp;&nbsp;
			<input type=button value="Cancel" onclick="fctcancel()">
		</td>
	</tr>
	</table>
	<?php if($msg!="") {?>
   <table border="2" cellpadding="4" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%">
      <tr>
        <td width="100%">
		<table width=100%>
			<tr>
			<td><?php echo $msg; ?></td>
			</tr>
		</table>
		</td>
	</tr>
	</table>
	<?php }?>

    <br>
    </td>
  </tr>
  <tr>
    <td width="100%">
    <p align="center"><font face="Verdana" size="2" color="#808080">
    .net</font></td>
  </tr>
</table>

<?php mysql_close();?>
</body>
</html>
first_step.JPG 62.4 KB please_check_info.JPG 116.31 KB second_step.JPG 40.58 KB
<?php ob_start() ?>
<?php

require("class.phpmailer.php");

session_start();

//Check to see if the user was already logged on
if ($_SESSION["login"] !=1)
{
header ('Location: index.php?Msg=3');

}
//echo $_SESSION["login"];

//Connect to DB
$dbcnx = mysql_connect('host', 'username', 'password');

if (!$dbcnx) {
	echo '<Font color=red> Could not connect to the database at this time, please try later';
	exit();
}

//Select the DB we want to deal with
mysql_select_db ("database");

?>
<?php ob_end_flush() ?>

<html>
<head>
<meta http-equiv="Content-Language" content="en-us">

<title>
 </title>
<script language=javascript>
function makeselection()
{
var nb=document.frm.nbr.value;
var chk;
var str="";
var s;

	for (var i = 1; i <= nb; i++)
	{
		a="document.frm.chk" + i;
		s=eval(a);
		if (s.checked)
		{
		if (str=="")
			str = "Promotion_ID=" + eval("document.frm.item" + i).value;
		else
			str = str + " OR " + "Promotion_ID=" + eval("document.frm.item" + i).value;
		}
	}
	//alert(str);
	window.opener.document.frm.users.value=str;
	window.close();
}
</script>
</head>
<body>

<table border="2" cellpadding="8" cellspacing="0" style="border-collapse: collapse" bordercolor="#808080" width="100%" bgcolor="#FFFFFF">
  <tr>
    <td width="100%" bgcolor="#DAF1DB">
	<table width=100%>
	<tr>
	<td align=left>
	<b><font face="Verdana">Promotion Emails</font></b><p align=right><input type=button name=btnsubmitt value="Select" onclick="makeselection()">&nbsp;&nbsp;&nbsp;
						<input type=button name=btncloset value="Cancel" onclick="window.close()"></p>
        </td>
	<td align=right>
        </td>
	</tr>
        </table>

    </td>
  </tr>
  <tr>
    <td width="100%">


   <table border="2" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%">
      <tr>
        <td width="100%">
		<table width=100%>
			<tr>
				<td>
						<form name=frm>
						<table width=100%>
						<tr>
						<td></td><td><font face=verdana size=2><b>Group Name</b></td><td><font face=verdana size=2><b>Full Name</b></td><td><font face=verdana size=2><b>Email</b></td>
						</tr>
						<?php
							$count=0;
							$sql="Select Promotion_ID,FName,LName,Email,PromoGroup.PromoGroup as grp from promotion,PromoGroup WHERE  promotion.PromoGroupID=PromoGroup.PromoGroupID order by grp,Email";
							$result = mysql_query($sql);
							while ($row = mysql_fetch_array($result))
							{
							$count=$count+1;
							echo "<tr>";
							echo "<td><input type=checkbox name=chk$count><input type=hidden name=item$count value=" . $row['Promotion_ID'] . "></td>";
							echo "<td><font face=verdana size=2>" . $row['grp'] . "</td>";
							echo "<td><font face=verdana size=2>" . $row['LName'] . $row['FName']. "</td>";
							echo "<td><font face=verdana size=2>" . $row['Email'] . "</td>";
							echo "</tr>";

							}
							echo "<input type=hidden name=nbr value=$count>";

						?>
						</table>

						<br>
						<center>
						<input type=button name=btnsubmit value="Select" onclick="makeselection()">&nbsp;&nbsp;&nbsp;
						<input type=button name=btnclose value="Cancel" onclick="window.close()">
						</center>
						</form>
				</td>
			</tr>

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


    </td>
  </tr>
  <tr>
    <td width="100%">
    <p align="center"><font face="Verdana" size="2" color="#808080">
   t</font></td>
  </tr>
</table>


<?php
mysql_close();
?>
</body>
</html>

First of all, why do you have different name for checkboxes ? You can create a checkbox array by giving the same name for the checkboxes. Then, on page submit, only those checkboxes which were selected will be posted to the next page. I don't know what exactly your script does as I can't figure out what's the relation between users.php and checked.php .

i will put a small note: in the admin use; i add e-mails ; so each e-mail is added in my script will lead to an added email checkbox in the users.php thru sql, that has been done perfectly

my script is to send e-mail to clients to the selected one,
; BUT when i select one checkbox is still sending to all clients, while the checkbox is working fine but i can not prgram to select only one checkbox email at a time to select to only for example to 1 client= it keeps sending to all

i mean i do step 1 , users will open; will give me the list of e-mails and in

step 2 ; i choose from the list

step 3 ; i click send - still sending to all or (if i chnage the phrase i included in the pic info ) will not send at all

and also thanks for having a reply from u

Attachments step3.JPG 44.15 KB

what you can do is

<input type="checkbox" name="emails[]" value="user1@domain.com" />

<input type="checkbox" name="emails[]" value="user2@domain.com" />

<input type="checkbox" name="emails[]" value="user3@domain.com" />

After the form submission you'll have an array with emails. The emails in checkboxes should be populated when you render the table.

You can access them using this:

<?php

$emails = empty($_REQUEST['emails']) ? array() : (array) $_REQUEST['emails'];

foreach ($emails as $email) {
   // do something
   send_email($email);
}
?>

Hi..
Try to do this....may be it will work..exactly i too dont know..

<form name=frm method =post>

what you can do is

<input type="checkbox" name="emails[]" value="user1@domain.com" />

<input type="checkbox" name="emails[]" value="user2@domain.com" />

<input type="checkbox" name="emails[]" value="user3@domain.com" />

After the form submission you'll have an array with emails. The emails in checkboxes should be populated when you render the table.

You can access them using this:

<?php
$artwork =@addslashes($_POST['emails']);
$artwork=(!empty($_POST['emails'])? array_map('stripslashes',$_POST['emails']) : ''); 


echo $mail_body='<style type=text/css><!--td {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px;}--></style>
<table width="50%"  border="0" align="center" cellpadding="1" cellspacing="0" bgcolor="#E7E7E7">
  <tr>
    <td><table width="100%"  border="0" align="center" cellpadding="5" cellspacing="0" bgcolor="#FFFFFF">
        <input type="hidden" name="emails" value="ok">
        <tr>
<td>Services </td>
          <td>:</td>
          <td>		 
		  '.(is_array($artwork)? implode(",",$artwork) : '').'

		  
		  </td>
</tr>
?>

just do this...

Dear helpful guys; i thanks for having nice replies, i got your ideas

but the thing is that; in my php files i have one ; that will add my e-mails directly to sql and i will attach the pic, so when i come back to To Users and select one Email from it

in which checkbox is already created for the e-mail not to put that one by one; the selection still taking all selected e-mails and not one; something is easy and i can not figure that out yet; pls help is needed as much you can ; you can add me on recoverysignals@hotmail.com
on msn so i be more helpful

Attachments pls_see_sql_pic.JPG 59.22 KB

dear guys

my script is based on 2 files of php; one is the SEND and one is the CHEKBOX selection
and the files are attached on the top of my forum and again thanks

regards

Helpful people

When i click send i got this message also when i select in To Users one e-mail ; and if i remove that phrase in php i get a green light ok ; but the e-mail is not send, selection still not working for one ;

This article has been dead for over six months. Start a new discussion instead.