PHP mail: Multiple recipients?

前端 未结 5 1663
暗喜
暗喜 2020-12-01 09:27

I have this code:



        
相关标签:
5条回答
  • 2020-12-01 09:38

    I just tested the codes you presented and before using them, people need to know that using this way (multiple addresses in 'to' field), every single person in that email can see all the destinatars.

    Also, if you're using Bcc, they'll also know the first person in the list.

    Be aware! :)

    0 讨论(0)
  • 2020-12-01 09:43

    According to Alex's answer above, recipients will know the first person in the list even if you're using BCC. A solution for this would be to send individual copies to each address one by one.

    $emails = ['a@example.com', 'b@example.com', 'c@example.com'];
    foreach ($emails as $email){ // or $result as $row
      mail(
        $email, // or $row['address']
        'Same Subject',
        'Same Content',
        'From: same_sender@example.com',
        '-f same_sender@example.com'
      );
    }
    
    0 讨论(0)
  • 2020-12-01 09:51
    while($row = mysql_fetch_array($result))
    {
        $addresses[] = $row['address'];
    }
    $to = implode(", ", $addresses);
    

    As specified on the mail() manual page, the "to" parameter of the function can take a comma-separated list of addresses.

    0 讨论(0)
  • 2020-12-01 09:56

    You just need to use GROUP_CONCAT to return the results separated by ','

    $result = mysql_query("SELECT GROUP_CONCAT(address) FROM email");
    
    0 讨论(0)
  • 2020-12-01 09:57

    Separate the addresses with commas.

    $to=array();
    while($row = mysql_fetch_array($result)) {
        array_push($to, $row['address']);
    }
    
    ...
    
    mail(implode(',', $to), $submit, $message, $headers);
    
    0 讨论(0)
提交回复
热议问题