473,405 Members | 2,262 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Selecting multiple checkboxes and sending mails to selected.

HI All....

cud any one provide me the code for :

Selecting mulitiple checkboxes and sending mail when clicked on submit button.

The checkboxes are retrived from the Mysql table .The code for the check boxes is here......

[PHP]
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td> <input type='checkbox' name='checkbox1'>" . $row['display_name'] . "</td>";
echo "<td>" . $row['skill_name'] . "</td>";
echo "<td>" . $row['skill_desc'] . "</td>";
echo "</tr>";
}
echo "</table>";
[/PHP]

Thanks & regards,
purush.
Jul 19 '07 #1
5 7394
ak1dnar
1,584 Expert 1GB
Try this code...
  • print your check boxes dynamically
  • Set the value=email address for them
  • Pass the imploded $to variable to your mail function
[PHP]mail($to, $subject, $body, $headers);[/PHP]

Sample Script
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. if(isset($_POST['frm_chk'])){
  3. $_Chk_box_value = $_POST['frm_chk'];
  4. $to = implode(',',$_Chk_box_value);
  5. echo 'Pass this to mail() funtion Recipients : '.$to;
  6. }
  7. ?>
  8. <html>
  9. <body>
  10. <form name="form1" action="" method="post">
  11. <!--
  12. Dynamically You Can Print the Check Boxes here....
  13. -->
  14. <input type="checkbox" name="frm_chk[]" value="user_1_at_domain_dot_com" />User 1
  15. <input type="checkbox" name="frm_chk[]" value="user_2_at_domain_dot_com" />User 2
  16. <input type="checkbox" name="frm_chk[]" value="user_2_at_domain_dot_com" />User 3
  17. <input type="checkbox" name="frm_chk[]" value="user_2_at_domain_dot_com" />User 4
  18. <!--
  19. .....With Other Elements
  20. -->
  21. <input name="" type="submit">
  22. </form>
  23. </body>
  24. </html>
  25.  
Jul 19 '07 #2
nathj
938 Expert 512MB
Hay All..

I need the code assistance for selecting multiple checkboxes(The checkboxes are fetched from the Mysql database tables and they are with while loop) and sending mail to the selected checkboxes.

Here is my code for the reference.This is fetched from the database.

[PHP]
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td> <input type='checkbox' name='checkbox1'>" . $row['display_name'] . "</td>";
echo "<td>" . $row['skill_name'] . "</td>";
echo "<td>" . $row['skill_desc'] . "</td>";
echo "</tr>";
}
echo "</table>";
[/PHP]
Hi,

Assuming this is within a form with a post method then the receiving page can read through the values of the checkboxes and send the emails as required.

However, the loop you have will set up any number of check boxes all with the same name. It would be worth using distinct names for the check boxes. Perhaps you could add a number to the end of the name using a loop counter. This would enable you to know what selections have been made after the form has been submitted.

I hope this is helpful, if not perhaps you could post the code of the page that is listed in the action part of the form tag.

nathj
Jul 19 '07 #3
ak1dnar
1,584 Expert 1GB
I have to merge this thread with another thread which was there at Articles section.because both are asking the same question.

nathj ,
I am sorry I couldn't find out a way to bumb back your post as the very next post of the original post.

-Ajaxrand
Jul 19 '07 #4
Thanks 4 ur kind reply...Will you mind if I need your assistance again....

Here is my total code...Here the check box is kept in loop.And their number depends on the data in the Mysql tables.So I cud n't initiate all of them.They must also be done dynamically.After I select the checkboxes(may be one or more) mail must be sent to expert(One or more,depending on the selection of the check box)...

[PHP]<html>
<body>

<?php
mysql_connect("localhost","root") or die(mysql_error());
mysql_select_db("db_soft") or die(mysql_error());

$result = mysql_query("SELECT sfa_experts.display_name, sfa_skills.skill_name, sfa_skills.skill_desc
FROM sfa_experts, sfa_skills, sfa_expert_skills
WHERE sfa_experts.expert_uid = sfa_expert_skills.expert_uid
AND sfa_skills.skill_uid = sfa_expert_skills.skill_uid");

echo "<table border='1' align=center >
<tr>
<th>Expert Name</th>
<th>Profile</th>
<th>Area of Experience</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";

echo "<td> <input type='checkbox' name='check[][]'>" . $row['display_name'] . "</td>";
echo "<td>" . $row['skill_name'] . "</td>";
echo "<td>" . $row['skill_desc'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close();
?>

Ask Question:

<TEXTAREA name="question" cols=55> </TEXTAREA><br><br>
<br><br>

<form method="POST" action="">
<input type="submit" name="action" value="AskExpert"/>
</form>
<?php

if ($_POST['action'] == "AskExpert")
{
$email="expert@gmail.com";
$mail = new COM('iMSMail.SendMail');
$mail->SpoolDir = 'C:\Program Files\...';
$mail->setheader('To',$email);
$mail->setheader('From','user@abc.com');
$mail->setheader('Subject','Ask your question!');
$mail->body='you can ask question by slecting appropriate expert';
$mail->sendmail();
print $mail->Result;
print "<br>Your email was sent to ";
print $mail->TotalRecipients;
print " recipients from a total of ";
print $mail->InputRecipients;


}


?>
</body>
</html>[/PHP]


Thanks & regards,
Purush.
Jul 20 '07 #5
nathj
938 Expert 512MB
Hi,

If you are setting the checkboxes dynamically in a loop yo ucan still follow ajaxrand's idea of assigning the value of the email address to the check box.

Then when the form is submitted you know how many checkboxes there were and, if they have been named with either a pre-fix or postfix of a number you can run a similar loop to build up the address list for the email. The variable can then be set as the 'To' list for the email.

That's the way I would think of tackling the second half of this problem. If you don't like the idea of naming the checkboxes as I have said then you could always keep track of them in an array as you build the form and then use the array to control the way you build the address list.

I hope this points you in the right direction, or at least gets you thinking about it.

nathj
Jul 20 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: jason | last post by:
How does one loop through the contents of a form complicated by dynamic construction of checkboxes which are assigned a 'model' and 'listingID' to the NAME field on the fly in this syntax:...
1
by: kannadasan | last post by:
Hi all I am using Datagrid where i place checkboxes in one column with some other columns.The purpose is, if i select the checkboxes and clicks the submit buton Email has to go to the selected...
7
by: Lau | last post by:
I need to send 1000 emails from an asp.net website. Normally I would use System.Web.Mail.MailMessage() to send thru an SMTP server. But the large amount of emails results in a timeout. My server...
2
by: Mortar | last post by:
i have a datagrid with 2 columns. the 1st column contains an id which will be used by the database for the selected checkbox records. the 2nd column is a template column containing a server...
1
by: Bob Loveshade | last post by:
I am looking for an example that shows how to select and highlight multiple rows in a DataGrid. My DataGrid is part of a Web User Control which is contained in an ASPX page. I haven't been...
3
by: kevcar40 | last post by:
Hi i have a form that allows the user to select criteria for searching on what i am trying to create now is a search for shifts i have three check boxes on the form ashift bshift cshift i...
2
by: areef.islam | last post by:
Hi, I am kinda new to javascript and I am having this problem with selecting multiple options from a select tag. Hope someone can help me out here. here is my code...
0
by: SirMikesALot | last post by:
I'm pretty good at Excel, but my skills in Visual Basic are very limited. I found script on-line that creates & opens a user form, allows you to select your worksheets, prints the selected...
0
by: TechnoAtif | last post by:
<?php include "dbconnect.php"; include "commonFunc.php"; ?> <!----------------------------------> <table width="80%" border="1" cellpadding="2" cellspacing="0"> <tr > <td...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.