Jump to content

Create mailing list by selecting rows


jcstanley

Recommended Posts

Hi

 

I currently have a table that shows the details of every member in the database.

 

What i am trying to achive is a way of providing the user with a method of selecting individual users ie.checkbox (and a select all function) to send a bulk email to.

 

I am familiar with the php mail fuinction but am not sure how to go about this so any ideas/examples would be great. 

 

Here is the code for what i have got so far:

 

mysql_select_db($database_psc, $psc);
$query_rsAllMembers = "SELECT * FROM members ORDER BY surname ASC";
$rsAllMembers = mysql_query($query_rsAllMembers, $psc) or die(mysql_error());
$row_rsAllMembers = mysql_fetch_assoc($rsAllMembers);
$totalRows_rsAllMembers = mysql_num_rows($rsAllMembers);

form id="allmembers" name="allmembers" method="post" action="">  
    <table width="100%" border="0" cellspacing="0" cellpadding="2">

      <tr>
        <td class="tablecontent"><div align="center"><strong>Forename</strong></div></td>
        <td class="tablecontent"><div align="center"><strong>Surname</strong></div></td>
        <td class="tablecontent"><div align="center"><strong>Telephone</strong></div></td>
        <td class="tablecontent"><div align="center"><strong>Email</strong></div></td>
        <td class="tablecontent"><div align="center"><strong>Last Logged in</strong></div></td>
        <td class="tablecontent"><div align="center"><strong>Mail</strong></div></td>
      </tr>
      <?php do { ?>
        <tr>
          <td height="44" class="tablecontent"><?php echo $row_rsAllMembers['fname']; ?></td>
          <td class="tablecontent"><?php echo $row_rsAllMembers['surname']; ?></td>
          <td class="tablecontent"><?php echo $row_rsAllMembers['telephone']; ?></td>
          <td class="tablecontent"><?php echo $row_rsAllMembers['email']; ?></td>
          <td class="tablecontent"><?php echo $row_rsAllMembers['login']; ?></td>
          <td class="tablecontent">
            <label>
              <input name="CheckboxMail" type="checkbox" id="CheckboxMail" value="<?php echo $rsAllMembers['email'];?>" />
              </label>
          </td>
        </tr>
        <?php } while ($row_rsAllMembers = mysql_fetch_assoc($rsAllMembers)); ?>
        
    </table> 

 

If you need more info please let me know

 

Thanks

 

Link to comment
https://forums.phpfreaks.com/topic/94684-create-mailing-list-by-selecting-rows/
Share on other sites

I know it is to do with arrays.  i renamed the check boxes CheckboxMail[] and the the $_POST['CheckboxMail'].

 

but how can i create a string to use with the mail()  eg [email protected], [email protected],.....

 

just not sure how to loop throught the array.

 

any suggestion?

thanks

I have managed to get the values of the array and display them on screen!

 

foreach($_POST['CheckboxMail'] as $key=>$value) { 
$string=("$value");
echo $string; 
}  

 

But i need to create a string in the format: [email protected], [email protected],...etc  and am not sure how to do it.

 

Any ideas?

 

Thanks

ok im nearly there now.

 

I have the following code which loops through and retrieves the values of the CheckboxMail Array.

 

 

$toCheck = $_POST['CheckboxMail']; 
$count    = count( $toCheck );

for( $i = 0; $i < $count; $i++ ) 
{
$value= ($_POST['CheckboxMail'][$i]);

$list=$list." ". $value;
echo $list;
}

 

 

The problem now is to with looping. Say i selected 3 rows, when $list is output to the screen i end up with:

 

[email protected] [email protected] [email protected] [email protected] [email protected] [email protected]

 

what I need is:

[email protected] [email protected] [email protected]

 

Where am i going wrong?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.