PHP - 巨大的数组和循环语句

发布于 2024-11-17 13:57:47 字数 857 浏览 5 评论 0原文

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

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

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

$toList = array('[email protected]', '[email protected]');

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

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

非常感谢您的帮助!

I have an old customer email list (about 1100 emails) and I would like to email them all.
This list is in a gigantic php array.

I am using sendgrid and they have a nice php howto located here: http://sendgrid.com/documentation/display/api/SMTPPHPExample

I am using their code and in one section they have:

$toList = array('[email protected]', '[email protected]');

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.

I'm not too php savvy so i have no idea how to set up this loop.

Thanks a lot for any help!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

童话 2024-11-24 13:57:47

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

I think you're talking about array array_chunk ( array $input , int $size[, bool $preserve_keys = false ] ). It splits an array into and array of smaller arrays based off of the value in $size.

止于盛夏 2024-11-24 13:57:47
> 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 库会自动为您完成此操作,您甚至不必担心这一点。如果您担心,您应该发送[电子邮件受保护]< /code> 一封电子邮件询问此事:)??


但如果你真的想拆分,你应该阅读 cwallenpoole 的答案我认为这非常好。但是在分割数组之后,您还应该 sleep 然后进行节流。

> 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.

Like other users said in the comments I don't think you should worry about overflowing sendgrid because they are sending the emails using a message queue or something not to kill there server because you are not the only user that is using sendgrid. According to the Sendgrid website they have some very big sites like Slideshare/Hootsuite/Get Satisfaction/FourSquare that sent a lot of emails.


In the comments you said:

> 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?

According to smtp best practices:

You must ensure that the header is
folded to line lengths under 1,000
characters. Failure to do this can
cause intermediate MTA's to split the
header for you on non-space
boundaries, which will cause spaces to
be inserted in the final resulting
e-mail.

I assume the PHP libraries does that for you automically and you don't have to even worry about that. If you worry about that you should sent [email protected] an email to ask about that :)??


But if you really want to split you should read cwallenpoole's answer which I think is pretty good. But after splitting the array you should also sleep then to throttle.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文