Reputation: 141
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 = "[email protected]";
$headers = "From: $from";
if(mail($to,$subject,$message,$headers)) {
$msg = "Edit en mail succesvol";
header("location: xxxxxxxx?msg=" . $msg);
}
Upvotes: 1
Views: 128
Reputation: 6246
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.
Upvotes: 1