2

我试图向 127 人发送邮件。我发现一封邮件的密件抄送部分只能有 99 个电子邮件地址。

所以我正在考虑将电子邮件数组分成 40 组,例如

我有一系列电子邮件

$emailaddresses = array(
    [0] => email1,
    [1] => email2, ...

所以我遍历数组并列出它们:

foreach($emailaddresses as $email) {
    $list .= $email.',';
}

然后我删除最后一个','并将它们添加到我的邮件对象中:

$mail->bcc = substr_replace($list ,"",-1);

如何遍历该数组直到 40 个地址,发送带有该列表的邮件,然后从 41->80 开始继续循环等等......?

4

4 回答 4

3

First of all; The easiest and probably cleanest way to send mail is to send one for each, meaning all of them have just their own address in the to-field.

foreach($arrayOfEmail as $email){
    mail($email, $subject, $message);
}

If you must send in chunks, this is my easiest go:

$segments = array_chunk($arrayOfEmail, 40);  // Split in chunks of 40 each
for each($segments as $segment){             // For each chunk:
    $mailTo = implode($segment, ',');        // Concatenate all to one recipient string
    (...)                                    // BCC to headers+++
    mail($myEmail, $subject, $message);      // Send mail
}
于 2013-10-21T19:58:03.043 回答
1

我认为 Dagon 是对的,你真的应该在 for 循环中向每个人发送 1 而不是使用 BCC,但这里有一个循环的外壳,可以让你开始寻找答案:

$count = 0;
foreach($emailaddresses as $email) {
    $count++;
    // Use the modulus to see if we are at a multiple of 40
    // Add the address to the BCC however you choose.
    if ($count % 40 == 0) {
        // Send the email and start a new one.
    }
}
于 2013-10-21T19:55:41.853 回答
0

why dont you use implode function as

$mail_list=implode(",",$emailaddresses)
it will give yor mail address as
email1,email2,email3............... , lastemail
于 2013-10-21T19:57:51.603 回答
0

您可以像这样遍历列表,而不是使用 array_chunk:

预先播种阵列作为测试:

$someArray = array();
for ($i = 0; $i <= 368; $i++) {
    $someArray[$i] = $i;
}

您将使用的逻辑:

$interval = 40;

$segments = floor($i/$interval);

for($i = 0; $i <= $segments; $i++) {
    $elements = join(", ", array_slice($someArray,($i*$interval),$interval));
    // extra logic here; i.e. test/validate addresses
    print $elements;
}
于 2013-10-21T20:06:20.567 回答