fixed progress email send
This commit is contained in:
@@ -41,7 +41,7 @@ function generateEmailTemplate($message)
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
.header img {
|
.header img {
|
||||||
max-width: 100px; /* Ridotto da 150px a 100px per rimpicciolire il logo */
|
max-width: 120px;
|
||||||
}
|
}
|
||||||
.content {
|
.content {
|
||||||
padding: 30px;
|
padding: 30px;
|
||||||
@@ -76,11 +76,10 @@ function generateEmailTemplate($message)
|
|||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="yoga-decoration"></div>
|
<div class="yoga-decoration"></div>
|
||||||
<div class="header">
|
<div class="header">
|
||||||
<img src="https://yogasoul.it/wp-content/uploads/2021/03/logotransizione_final2.png"
|
<img src="https://yogasoul.it/wp-content/uploads/2021/03/logotransizione_final2.png"
|
||||||
alt="YogaSoul - My WordPress Blog"
|
alt="YogaSoul"
|
||||||
width="120"
|
width="120"
|
||||||
style="display: block; width: 120px; max-width: 120px; height: auto; margin: 0 auto;">
|
style="display: block; width: 120px; max-width: 120px; height: auto; margin: 0 auto;">
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<p>$message</p>
|
<p>$message</p>
|
||||||
@@ -183,7 +182,7 @@ try {
|
|||||||
$message .= '. Non inviate (' . count($failed) . '): ' . implode(', ', $failed);
|
$message .= '. Non inviate (' . count($failed) . '): ' . implode(', ', $failed);
|
||||||
}
|
}
|
||||||
|
|
||||||
echo json_encode(['success' => true, 'message' => $message]);
|
echo json_encode(['success' => true, 'message' => $message, 'sent' => $sent, 'failed' => $failed]);
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
error_log('Errore in send_email.php: ' . $e->getMessage() . ' in ' . $e->getFile() . ' at line ' . $e->getLine());
|
error_log('Errore in send_email.php: ' . $e->getMessage() . ' in ' . $e->getFile() . ' at line ' . $e->getLine());
|
||||||
echo json_encode(['success' => false, 'message' => "Errore nell'invio dell'email: " . $e->getMessage()]);
|
echo json_encode(['success' => false, 'message' => "Errore nell'invio dell'email: " . $e->getMessage()]);
|
||||||
|
|||||||
+98
-25
@@ -907,11 +907,23 @@ Ti ringraziamo per la collaborazione e per l’attenzione alla sicurezza di tutt
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Invio effettivo email
|
// Invio effettivo email: a gruppi, con barra di avanzamento
|
||||||
|
var invioInCorso = false;
|
||||||
|
|
||||||
|
window.addEventListener('beforeunload', function(e) {
|
||||||
|
if (invioInCorso) {
|
||||||
|
e.preventDefault();
|
||||||
|
e.returnValue = '';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
$('#sendEmailBtn').on('click', function() {
|
$('#sendEmailBtn').on('click', function() {
|
||||||
|
if (invioInCorso) return;
|
||||||
|
|
||||||
var subject = $('#emailSubject').val(),
|
var subject = $('#emailSubject').val(),
|
||||||
body = $('#emailBody').val();
|
body = $('#emailBody').val();
|
||||||
var recipients = $('#emailRecipients').val();
|
var recipients = JSON.parse($('#emailRecipients').val() || '[]');
|
||||||
|
|
||||||
if (!subject || !body) {
|
if (!subject || !body) {
|
||||||
alertBox({
|
alertBox({
|
||||||
title: 'Errore',
|
title: 'Errore',
|
||||||
@@ -920,31 +932,92 @@ Ti ringraziamo per la collaborazione e per l’attenzione alla sicurezza di tutt
|
|||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (recipients.length === 0) {
|
||||||
$.post('send_email.php', {
|
alertBox({
|
||||||
subject: subject,
|
|
||||||
body: body,
|
|
||||||
recipients: recipients
|
|
||||||
}, null, 'json')
|
|
||||||
.done(function(resp) {
|
|
||||||
if (resp.success) {
|
|
||||||
alertBox({
|
|
||||||
title: 'Fatto',
|
|
||||||
text: resp.message,
|
|
||||||
icon: 'success'
|
|
||||||
});
|
|
||||||
$('#emailModal').modal('hide');
|
|
||||||
} else alertBox({
|
|
||||||
title: 'Errore',
|
|
||||||
text: resp.message,
|
|
||||||
icon: 'error'
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.fail((xhr) => alertBox({
|
|
||||||
title: 'Errore',
|
title: 'Errore',
|
||||||
text: 'Errore durante l\'invio: ' + (xhr.responseText || xhr.statusText || 'nessuna risposta').substring(0, 400),
|
text: 'Nessun destinatario.',
|
||||||
icon: 'error'
|
icon: 'error'
|
||||||
}));
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
invioInCorso = true;
|
||||||
|
$('#sendEmailBtn').prop('disabled', true);
|
||||||
|
$('#emailModal').modal('hide');
|
||||||
|
|
||||||
|
var BATCH = 5; // email per ogni richiesta
|
||||||
|
var total = recipients.length,
|
||||||
|
done = 0,
|
||||||
|
sent = 0,
|
||||||
|
failed = [];
|
||||||
|
|
||||||
|
alertBox({
|
||||||
|
title: 'Invio in corso…',
|
||||||
|
html: '<p id="sendProgressText">0 di ' + total + '</p>' +
|
||||||
|
'<div class="progress" style="height:22px;">' +
|
||||||
|
'<div id="sendProgressBar" class="progress-bar progress-bar-striped progress-bar-animated" style="width:0%">0%</div>' +
|
||||||
|
'</div>' +
|
||||||
|
'<p class="mt-3 mb-0 text-muted" style="font-size:13px;">Non chiudere questa pagina finché l\'invio non è terminato.</p>',
|
||||||
|
allowOutsideClick: false,
|
||||||
|
allowEscapeKey: false,
|
||||||
|
showConfirmButton: false
|
||||||
|
});
|
||||||
|
|
||||||
|
function aggiorna() {
|
||||||
|
var pct = Math.round(done / total * 100);
|
||||||
|
$('#sendProgressBar').css('width', pct + '%').text(pct + '%');
|
||||||
|
$('#sendProgressText').text(done + ' di ' + total);
|
||||||
|
}
|
||||||
|
|
||||||
|
function fine() {
|
||||||
|
invioInCorso = false;
|
||||||
|
$('#sendEmailBtn').prop('disabled', false);
|
||||||
|
var html = 'Email inviate: <strong>' + sent + '</strong> su ' + total + '.';
|
||||||
|
if (failed.length) {
|
||||||
|
html += '<br><br>Non inviate (' + failed.length + '):<br>' +
|
||||||
|
$('<div>').text(failed.join(', ')).html();
|
||||||
|
}
|
||||||
|
alertBox({
|
||||||
|
title: failed.length ? 'Invio completato con errori' : 'Invio completato',
|
||||||
|
html: html,
|
||||||
|
icon: failed.length ? 'warning' : 'success'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function inviaGruppo(start) {
|
||||||
|
if (start >= total) {
|
||||||
|
fine();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var gruppo = recipients.slice(start, start + BATCH);
|
||||||
|
$.post('send_email.php', {
|
||||||
|
subject: subject,
|
||||||
|
body: body,
|
||||||
|
recipients: JSON.stringify(gruppo)
|
||||||
|
}, null, 'json')
|
||||||
|
.done(function(resp) {
|
||||||
|
if (resp && resp.success) {
|
||||||
|
sent += resp.sent || 0;
|
||||||
|
failed = failed.concat(resp.failed || []);
|
||||||
|
} else {
|
||||||
|
failed = failed.concat(gruppo.map(function(r) {
|
||||||
|
return r.email;
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.fail(function() {
|
||||||
|
failed = failed.concat(gruppo.map(function(r) {
|
||||||
|
return r.email;
|
||||||
|
}));
|
||||||
|
})
|
||||||
|
.always(function() {
|
||||||
|
done += gruppo.length;
|
||||||
|
aggiorna();
|
||||||
|
inviaGruppo(start + BATCH);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
inviaGruppo(0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user