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