Click to See Complete Forum and Search --> : Slight Problem With Checkboxes/Emailing


Jeffro
09-06-2008, 01:13 PM
I am in the process of creating a page where I can email people in my database by checking a box next to their username.

The way I have it set up, the page where I type in my message his this script to get all of the emails and give them a checkbox. $sql = "select * from member";
$result=mysql_query($sql);
$num=mysql_numrows($result);
$i=0;
while ($i < $num) {
$username=mysql_result($result,$i,"username");
$email=mysql_result($result,$i,"email");
echo "<input type='checkbox' name='email$i' value='$email'>$username<br>";
$i++; }

Then, after you submit the form, I go to a page with phpMailer. Now, my problem is getting each email address. Here's my code:
$i = 0;
while($i <$numpeeps) {
$emaili = "email$i";
if ($emaili) {
$mail->AddBCC("$email0");
echo "$email0";
}
$i++;
}

I need to get it so that it will go through each checkbox name ($email0, $email1, ect) until it reaches the max ($numpeeps) in this part of the script:
$mail->AddBCC("$email0");
echo "$email0";

Jeffro
09-07-2008, 07:15 PM
Please, I really need help on this. I'm thinking that maybe in the first step I could put the email addresses into a database then pull them out in the second step (where they get emailed)?

jim_keller
09-09-2008, 05:03 PM
I"m a little confused as to what you need to do. It seems like you should be adding:


$mail->AddBCC($emaili);


instead of


$mail->AddBCC($email0);


since the latter always adds the same address ($email0).

If it's interrupting the loop you're confused about, you can use:


if ($emaili) {
$mail->AddBCC("$email0");
echo "$email0";
}
else {
break; //exit the loop if $emaili doesn't have a value
}



the Fuse PHP MVC Framework (http://www.phpfuse.net)
Why you should be doing your PHP development in FUSE (http://jimkeller.blogspot.com/2008/09/why-you-should-do-your-php-development.html)

Jeffro
09-10-2008, 02:59 PM
It's kinda complicated, but I need to have go through a loop with $email0, $email1, ect, but only if they exist. Until it gets to the highest possible $email# (number is $numpeeps) Does that clarify it a bit?