extended bulkmail

This commit is contained in:
Torsten Schulz
2024-02-14 15:37:18 +01:00
parent d37805a798
commit 8cebbf17d2

View File

@@ -8,8 +8,10 @@ class Bulkmail extends Renderer {
['label' => 'Signatur', 'type' => 'combobox', 'size' => 5, 'name' => 'signature', 'combine_with_next_line' => false, ['label' => 'Signatur', 'type' => 'combobox', 'size' => 5, 'name' => 'signature', 'combine_with_next_line' => false,
'values' => ['Persönliche Signatur', 'Vorstandssignatur'], 'values' => ['Persönliche Signatur', 'Vorstandssignatur'],
], ],
['label' => 'An normale Mitglieder', 'type' => 'checkbox', 'size' => 50, 'name' => 'custommembers', 'size' => 1, 'value' => 1, 'combine_with_next_line' => false],
['label' => 'An den Vorstand', 'type' => 'checkbox', 'size' => 50, 'name' => 'board', 'size' => 1, 'value' => 1, 'combine_with_next_line' => false],
]; ];
protected string $formSendButtonLabel = 'Email an alle aktiven Mitglieder absenden'; protected string $formSendButtonLabel = 'Email an ausgewählte Empfängergruppe senden';
protected function formAction(): void { protected function formAction(): void {
$this->sendEmail($this->generateSubject(), $this->generateBody(), $this->generateSignature(filter_input(INPUT_POST, 'signature'))); $this->sendEmail($this->generateSubject(), $this->generateBody(), $this->generateSignature(filter_input(INPUT_POST, 'signature')));
@@ -26,23 +28,32 @@ class Bulkmail extends Renderer {
protected function sendEmail(string $subject, string $body, string $signature): void { protected function sendEmail(string $subject, string $body, string $signature): void {
$mail = $this->initSmtpMailer();; $mail = $this->initSmtpMailer();;
$bccRecipients = $this->loadReceivers(); $bccRecipients = $this->loadReceivers();
$sendToCustomMembers = intval(filter_input(INPUT_POST, 'custommembers')) === 1;
$sendToBoard = intval(filter_input(INPUT_POST, 'board')) === 1;
$sendTo = [];
try { try {
$mail->setFrom('foerderverein-ajs@gmx.de', 'Förderverein der Steffi-Jones-Schule'); $mail->setFrom('foerderverein-ajs@gmx.de', 'Förderverein der Steffi-Jones-Schule');
$mail->addReplyTo('foerderverein-ajs@gmx.de', 'Förderverein der Steffi-Jones-Schule'); $mail->addReplyTo('foerderverein-ajs@gmx.de', 'Förderverein der Steffi-Jones-Schule');
$mail->addAddress('vorstand@fvajs.de', 'Vorstand des FVAJS'); $mail->addAddress('vorstand@fvajs.de', 'Vorstand des FVAJS');
foreach ($bccRecipients as $recipient) { foreach ($bccRecipients as $recipient) {
$mail->addBCC($recipient); if (($sendToCustomMembers && $recipient['position'] === null)
|| ($sendToBoard && $recipient['position'] !== null)) {
$mail->addBCC($recipient['email']);
$sendTo[] = $recipient['email'];
} else {
var_dump($recipient['position']);
}
} }
$this->sendMail($mail, $subject, $body, $signature); $this->sendMail($mail, $subject, $body, $signature);
} catch (Exception $e) { } catch (Exception $e) {
$this->templateName = 'error_smtp'; $this->templateName = 'error_smtp';
} }
$this->templateName = 'bulkmail_success'; $this->templateName = 'bulkmail_success';
$this->content['recipients'] = implode('<br />', $bccRecipients); $this->content['recipients'] = implode('<br />', $sendTo);
} }
protected function loadReceivers(): array { protected function loadReceivers(): array {
$query = 'SELECT c.first_name, c.last_name, c.email, c.salt $query = 'SELECT c.first_name, c.last_name, c.email, c.salt, c.position_id
FROM clubmember c FROM clubmember c
JOIN clubmember_status cs JOIN clubmember_status cs
ON cs.id = c.membership_status ON cs.id = c.membership_status
@@ -50,7 +61,7 @@ class Bulkmail extends Renderer {
$dbResult = mysqli_query($this->dbConnection, $query); $dbResult = mysqli_query($this->dbConnection, $query);
$recipientsList = []; $recipientsList = [];
while ($row = mysqli_fetch_assoc($dbResult)) { while ($row = mysqli_fetch_assoc($dbResult)) {
$recipientsList[] = $this->decode($row['email'], $row['salt']); $recipientsList[] = ['email' => $this->decode($row['email'], $row['salt']), 'position' => $row['position_id'] ];
} }
return $recipientsList; return $recipientsList;
} }