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
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 john@smith.com, x@y.com,.....

 

just not sure how to loop throught the array.

 

any suggestion?

thanks

Link to comment
Share on other sites

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: user@example.com, 123@xyz.com,...etc  and am not sure how to do it.

 

Any ideas?

 

Thanks

Link to comment
Share on other sites

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:

 

john@smith.com john@smith.com example@example.com john@smith.com example@example.com 123@xyz.com

 

what I need is:

john@smith.com example@example.com 123@xyz.com

 

Where am i going wrong?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.