Dan*_*Dan 2 php phpmailer amazon-web-services amazon-ses
我有一个在线软件,可以向Amazon SES发送电子邮件.目前我有一个cron作业,通过SMTP发送电子邮件与phpmailer发送消息.目前我必须将发送限制最大限制为每分钟300左右,以确保我的服务器没有超时.我们看到增长,最终我想发送到10,000或更多.
有没有更好的方式发送到亚马逊SES,或者这是其他人做的,但只有更多的服务器运行工作负载?
提前致谢!
您可以尝试使用AWS SDK for PHP.您可以通过SES API发送电子邮件,SDK允许您并行发送多封电子邮件.这是一个代码示例(未经测试且仅部分完成)以帮助您入门.
<?php
require 'vendor/autoload.php';
use Aws\Ses\SesClient;
use Guzzle\Service\Exception\CommandTransferException;
$ses = SesClient::factory(/* ...credentials... */);
$emails = array();
// @TODO SOME SORT OF LOGIC THAT POPULATES THE ABOVE ARRAY
$emailBatch = new SplQueue();
$emailBatch->setIteratorMode(SplQueue::IT_MODE_DELETE);
while ($emails) {
// Generate SendEmail commands to batch
foreach ($emails as $email) {
$emailCommand = $ses->getCommand('SendEmail', array(
// GENERATE COMMAND PARAMS FROM THE $email DATA
));
$emailBatch->enqueue($emailCommand);
}
try {
// Send the batch
$successfulCommands = $ses->execute(iterator_to_array($emailBatch));
} catch (CommandTransferException $e) {
$successfulCommands = $e->getSuccessfulCommands();
// Requeue failed commands
foreach ($e->getFailedCommands() as $failedCommand) {
$emailBatch->enqueue($failedCommand);
}
}
foreach ($successfulCommands as $command) {
echo 'Sent message: ' . $command->getResult()->get('MessageId') . "\n";
}
}
// Also Licensed under version 2.0 of the Apache License.
Run Code Online (Sandbox Code Playgroud)
您还可以考虑使用Guzzle BatchBuilder和朋友来使其更加强大.
您需要对此代码进行微调,但您可能会获得更高的电子邮件吞吐量.
| 归档时间: |
|
| 查看次数: |
2209 次 |
| 最近记录: |