Create mailing list by selecting rows

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jcstanley
    New Member
    • Mar 2008
    • 4

    Create mailing list by selecting rows

    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:

    Code:
    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
  • satas
    New Member
    • Nov 2007
    • 82

    #2
    All you need to do is to generate string following format:
    Code:
    user@example.com, anotheruser@example.com
    And then pass it to mail() function.

    So what is the problem? Just walk through $_POST[] array and gather selected checkboxes.

    Comment

    • jcstanley
      New Member
      • Mar 2008
      • 4

      #3
      thanks but could you give me an example of how to use the $_POST[] array as i have never used it.

      cheers

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        Originally posted by jcstanley
        thanks but could you give me an example of how to use the $_POST[] array as i have never used it.

        cheers
        The $_POST array is a simple keyed (associative) array.
        After you submitted the form, issue in the script that is called, the following command. That will show you how the $_POST array is constructed in your case.[php]echo '<pre>'; print_r($_POST) ;[/php]Ronald

        Comment

        • jcstanley
          New Member
          • Mar 2008
          • 4

          #5
          ok im nearly there now.

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

          Code:
          $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?

          Comment

          • Markus
            Recognized Expert Expert
            • Jun 2007
            • 6092

            #6
            You should really use a foreach loop to traverse through the POST array, as that is what foreach is intended for.
            Cant really help you as i have class in... -1mins.

            Comment

            • satas
              New Member
              • Nov 2007
              • 82

              #7
              Code:
              foreach($_POST['CheckboxMail'] as $key => $email) {
                $list .= " ".$email;
              }
              print $list;

              Comment

              • jcstanley
                New Member
                • Mar 2008
                • 4

                #8
                thank you satas!!!!

                simple solution but it was driving me crazy!!!!

                Comment

                • satas
                  New Member
                  • Nov 2007
                  • 82

                  #9
                  You are welcome. It always a bit difficult at first.

                  Comment

                  Working...