batch email send
This commit is contained in:
parent
dde483ee20
commit
9b9e5a2ef7
1 changed files with 29 additions and 20 deletions
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
set_time_limit(600);
|
||||
|
||||
return [
|
||||
'pattern' => '/send-newsletter.json',
|
||||
'method' => 'POST',
|
||||
|
|
@ -26,7 +28,7 @@ return [
|
|||
|
||||
$recipients = $data->isTest
|
||||
? $kirby->users()->pluck('email', null, true)
|
||||
: page('lettre')->subscribers()->toStructure()->pluck('email', true, true);
|
||||
: page('lettre')->subscribers()->toStructure()->pluck('email', ',', true);
|
||||
|
||||
if (empty($recipients)) {
|
||||
return json_encode([
|
||||
|
|
@ -47,7 +49,11 @@ return [
|
|||
$sentEmails = [];
|
||||
$errors = [];
|
||||
|
||||
foreach ($recipients as $recipient) {
|
||||
$batchSize = 5;
|
||||
$pauseBetweenBatches = 1;
|
||||
|
||||
foreach (array_chunk($recipients, $batchSize) as $batch) {
|
||||
foreach ($batch as $recipient) {
|
||||
try {
|
||||
$kirby->email([
|
||||
'from' => $from,
|
||||
|
|
@ -69,6 +75,9 @@ return [
|
|||
}
|
||||
}
|
||||
|
||||
sleep($pauseBetweenBatches);
|
||||
}
|
||||
|
||||
if (!$data->isTest) {
|
||||
$emailPage->changeStatus('listed');
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue