1

For the email updates function of my website I don't want all the users which receive the email to see all other members their email addresses

How can I disable this/turn this off?

My code:

if($query -> execute()) {


    if($sendmsg == 1) {
    $emailquery = $db->prepare("SELECT email FROM tbl_users WHERE emailupdates = 1");
    $emailquery -> execute();

    $elist = "";
    while($mail = $emailquery->fetch(PDO::FETCH_OBJ)) {
        $elist .= $mail->email . ", ";
    }


    $emails = substr($elist, 0, -2);

    $link = "http://xxxxx.nl/kalenderdetail/" . $id;

    $to         =   $emails;
    $subject    =   "Nieuwe wedstrijd toegevoegd aan kalender xxxxx.nl";
    $message    .=  "Beste lid van xxxx.nl,\n\n";
    $message    .=  "Er is zojuist een nieuwe wedstrijd toegevoegd aan de website.\n";
    $message    .=  "Titel van de wedstrijd: " . $titel ."\n";
    $message    .=  "Locatie: " . $locatie . "\n";
    $message    .=  "Bekijk het hele kalenderitem: ". $link . "\n\n";
    $message    .=  "Met sportieve groeten,\n";
    $message    .=  "xxxxxx\n";
    $from       =   "info@xxxxx.nl";
    $headers    =   "From: $from";
    if(mail($to,$subject,$message,$headers)) {
        $msg = "Edit en mail succesvol";
        header("location: xxxxxxxx?msg=" . $msg);
    }
user3428971
  • 141
  • 1
  • 1
  • 10
  • 1
    What about sending the email in the while loop so rather than one email to multiple addresses, you send multiple emails on one address. You could also give BCC (Blind carbon copy) a try, see if that works for you. http://stackoverflow.com/a/9525476/993600 – TMH Feb 23 '15 at 13:25
  • Good stuff! Mind accepting this as the answer (just posted) so others may also find this helpful? – TMH Feb 23 '15 at 14:12

1 Answers1

1

You could either put the code to send the email within the while loop, so rather than one email to multiple addresses, you send multiple emails on one address, but this could lead to spam issues.

Alternatively you could use BCC (Blind Carbon Copy) See here

A side note not related to the question, I personally find the chopping 2 characters method you use a little messy. You could achieve the same result this way.

$elist = array();
while($mail = $emailquery->fetch(PDO::FETCH_OBJ)) {
    $elist[] = $mail->email;
}


$emails = implode(', ', $elist);

The benefit being if you change the delimiter (,), you don't need to edit the substr method aswell, but as I say this is just my personal opinion on this.

TMH
  • 6,096
  • 7
  • 51
  • 88