3

我有一个旧的客户电子邮件列表(大约 1100 封电子邮件),我想给他们都发电子邮件。该列表位于一个巨大的 php 数组中。

我正在使用 sendgrid,他们在这里有一个不错的 php howto:http: //sendgrid.com/documentation/display/api/SMTPPHPExample

我正在使用他们的代码,在一个部分中他们有:

$toList = array('destination1@example.com', 'destination2@example.com');

现在,为了不溢出 sendgrids 服务器或陷入垃圾邮件过滤器,我只想一次只发送 100 封电子邮件的批次,我如何从我的大阵列中抓取 100 封电子邮件,将它们放入这个阵列,运行 sendgrid 登录,发送电子邮件,然后返回,获取下一个 100 并再次运行循环。

我不是太精通php,所以我不知道如何设置这个循环。

非常感谢您的帮助!!

4

2 回答 2

4

我想你在谈论array array_chunk ( array $input , int $size[, bool $preserve_keys = false ] ). 它根据 $size 中的值将一个数组拆分为多个较小数组的数组。

于 2011-06-28T02:06:02.420 回答
2
> Now, to not overflow sendgrids servers
> or get caught in spam filters I would
> like to only send batches of 100
> emails at a time, how can I grab 100
> emails from my big array, put them
> into this array, run through the
> sendgrid login, send email, then go
> back, grab the next 100 and run the
> loop again.

就像其他用户在评论中所说的那样,我认为您不应该担心 sendgrid 溢出,因为他们使用消息队列发送电子邮件或不杀死那里的服务器,因为您不是唯一使用 sendgrid 的用户。根据 Sendgrid 网站,他们有一些非常大的网站,例如 Slideshare/Hootsuite/Get Satisfaction/FourSquare,它们发送了大量电子邮件。


在你说的评论中:

> The list is actually about 1100 people
> (just edited the original question),
> also sendgrid wants you to break the
> lines at 1000 characters, so i'm
> guessing sticking all 1000 emails will
> break that. Marc, do you know how to
> change it to BCC?

根据smtp 最佳实践

您必须确保将页眉折叠到 1,000 个字符以下的行长。不这样做可能会导致中间 MTA 在非空格边界上为您拆分标题,这将导致在最终生成的电子邮件中插入空格。

我假设 PHP 库会自动为您执行此操作,您甚至不必担心。如果您担心,您应该发送support@sendgrid.com一封电子邮件询问:)??


但是,如果您真的想拆分,则应该阅读cwallenpoole 的答案,我认为这非常好。但是在拆分阵列后,您还应该休眠然后进行节流。

于 2011-06-28T04:30:38.693 回答