简体   繁体   中英

php not show email addresses in email

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);
    }

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM