1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

PHP and MySQL Mailout

Discussion in 'HTML, Graphics & Programming' started by AndyCr15, May 27, 2018.

  1. AndyCr15

    Soldato

    Joined: Apr 28, 2011

    Posts: 7,212

    Location: London, UK

    Can anyone give me some pointers on the best way to do this.

    I have a table with people in with the usual details, including an email address, their name and a unique key.

    At the moment I'm setting up a form, iterating through the table displaying their name and a tick box, the id being the unique key.

    Code:
    while($row = mysqli_fetch_array($result)) {
                            $team=strtolower($row['team']);
    
                            if($row['email'] == "") {
                                $team = 'white';
                            }
    
                            ?>
                            <div class="col-sm-30 <?php echo $team.'Background'; ?>">
                                <input class="form-group-input" type="checkbox" value="<?php echo $row['uniqueid']; ?>" name="<?php echo $row['uniqueid']; ?>" id="<?php echo $row['uniqueid']; ?>" <?php if($team == 'white') { echo 'disabled'; } ?>>
                                <label class="form-checkbox form-label-inlin" for="<?php echo $row['uniqueid']; ?>">
                                <?php echo checkPartnerName($row['uniqueid']); ?>
                                </label>
                            </div>
                            <?php
                        }
    When it then posts, how am I best to go through getting the people's details? Can I iterate through $_POST?

    Does that all make sense?

    I'm sure there's a better way to do this though, I just don't know how?
     
  2. antijoke

    Caporegime

    Joined: Jan 28, 2003

    Posts: 36,770

    Location: Stratford-Upon-Avon

    What are trying to do? Automatically send them an email?
     
  3. AndyCr15

    Soldato

    Joined: Apr 28, 2011

    Posts: 7,212

    Location: London, UK

    Yes, the ones that have been ticked would get the email.
     
  4. antijoke

    Caporegime

    Joined: Jan 28, 2003

    Posts: 36,770

    Location: Stratford-Upon-Avon

    What exactly are you trying to do?

    Is this just a visual thing of who has been sent an email or when you manually tick the box it sends them an email?
     
  5. touch

    Capodecina

    Joined: Oct 28, 2006

    Posts: 10,330

    Location: Sufferlandria

    Don't use the $_POST to send the details, that could be manipulated. Post a list of the uniqueid values from the selected checkboxes then go and retrieve the email addresses from the database for each id.
     
  6. AndyCr15

    Soldato

    Joined: Apr 28, 2011

    Posts: 7,212

    Location: London, UK

    Thanks for the replies.

    It brings a list of everyone in the database. You tick ones you want to receive the email. Press submit and they all get sent an email.

    Yes, that's what I'm doing above, although I'm asking if I can iterate through $_POST to do so. Is there a better way to do it? Are you saying I can/should send them all in one post and then split them back up and iterate on the next page?
     
  7. touch

    Capodecina

    Joined: Oct 28, 2006

    Posts: 10,330

    Location: Sufferlandria

    Ah, i see.

    In that case, no. You can't iterate through $_POST, you can only post one object per request.
    That object can be an array of other objects, so you can post everything at once but you'd iterate through an attribute of $_POST rather than the post object itself eg. "foreach($_POST->customerarray as customer)" rather than "foreach($_POST as customer)"

    It could also be done with a separate post for each checkbox. So every time you tick a box, it fires off a single post request to email that customer. Probably not good UI for this scenario as there'd be no way to undo it if you ticked a box by mistake.
     
  8. AndyCr15

    Soldato

    Joined: Apr 28, 2011

    Posts: 7,212

    Location: London, UK

    Okay thanks, so I guess I would use some Javascript to collect the uniqueid's of everything that is ticked when submit is clicked, put them all into an array, then post the array?
     
  9. touch

    Capodecina

    Joined: Oct 28, 2006

    Posts: 10,330

    Location: Sufferlandria

    Yep, I would use java to do it but I think it could also be done in just php+html. I can't remember how exactly to do it but you can group the checkboxes together (possibly just name them all the same?) and it'll submit an array of values from all the checkboxes.
     
  10. AndyCr15

    Soldato

    Joined: Apr 28, 2011

    Posts: 7,212

    Location: London, UK

    Thanks, I'll look into that then.