Hi,
I have a list of names, emails, a checkbox and a message box, the names and emails are from a database. What I am trying to do to select say 5 of the names from the list via the checkbox and send an email to those who I have picked.
I can't seem to get my head around the foreach function, is it that there has to be a foreach function to collect the email addresses and to see which user has been selected or do they come under the same one.
I have tried to do some of the coding myself, but fear I am getting more and more confused, some help would be great. Here is what I have done so far.
---------------
Thanks & regards
Lokananth
Live chat By miOOt
Typically the ids of the checkboxes will be able to pull up the data to send the email. You would only need 1 foreach loop if that is the case.
Code:
foreach($checkbox as $id){
//pull up the info from mysql or other info using $id.
//send the email.
}
You might want to play around with checkboxes for a while and see how it is passed as a post variable and how you can manipulate it. I am working with something similar where the user can click a check box, and with the selected ones, they can perform a set of given actions (delete, update, move, etc).
I'm sorry I can't give you exact code because I am not sure exactly what/how you are doing this. Good luck.
Here is a simple program that will send a message to the name/email pairs you have in your database.
One thing to consider though, is the amount of time it will take to send the emails.
If it takes too long then the program may timeout.
So you may want to send only 10 or 20 at a time.
You could set a limit in your query to 10 or 20, then just page through the records if you have more then the limit is set for.
You will need to have a table in your database with columns 'name' and 'email' for the query to work.
Otherwise change the column names in the query to match the column names in the table.
And change the values of
$host
$user
$password
$db
$table
to match your configuration.