extended bulkmail
This commit is contained in:
@@ -8,8 +8,10 @@ class Bulkmail extends Renderer {
|
||||
['label' => 'Signatur', 'type' => 'combobox', 'size' => 5, 'name' => 'signature', 'combine_with_next_line' => false,
|
||||
'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 {
|
||||
$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 {
|
||||
$mail = $this->initSmtpMailer();;
|
||||
$bccRecipients = $this->loadReceivers();
|
||||
$sendToCustomMembers = intval(filter_input(INPUT_POST, 'custommembers')) === 1;
|
||||
$sendToBoard = intval(filter_input(INPUT_POST, 'board')) === 1;
|
||||
$sendTo = [];
|
||||
try {
|
||||
$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->addAddress('vorstand@fvajs.de', 'Vorstand des FVAJS');
|
||||
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);
|
||||
} catch (Exception $e) {
|
||||
$this->templateName = 'error_smtp';
|
||||
}
|
||||
$this->templateName = 'bulkmail_success';
|
||||
$this->content['recipients'] = implode('<br />', $bccRecipients);
|
||||
$this->content['recipients'] = implode('<br />', $sendTo);
|
||||
}
|
||||
|
||||
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
|
||||
JOIN clubmember_status cs
|
||||
ON cs.id = c.membership_status
|
||||
@@ -50,7 +61,7 @@ class Bulkmail extends Renderer {
|
||||
$dbResult = mysqli_query($this->dbConnection, $query);
|
||||
$recipientsList = [];
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user