mirror of
https://github.com/slawkens/myaac.git
synced 2025-04-27 09:49:22 +02:00

* Fix alert class name * feature: csrf protection * Cosmetics * Fix token generate * Admin Panel: changelogs csrf protection * news/id route * Refactor admin newses + add csrf * Use admin.links instead * Admin panel: Pages csrf * Menus: better csrf + add success message on reset colors * Plugins csrf * Move definitions * add info function, same as note($message) * Update mailer.php * Fix new page/news links * clear_cache & maintenance csrf * Formatting * Fix news type * Fix changelog link * Add new changelog link * More info to confirm dialog * This is always true
86 lines
2.2 KiB
PHP
86 lines
2.2 KiB
PHP
<?php
|
|
/**
|
|
* Mailer
|
|
*
|
|
* @package MyAAC
|
|
* @author Slawkens <slawkens@gmail.com>
|
|
* @copyright 2019 MyAAC
|
|
* @link https://my-aac.org
|
|
*/
|
|
defined('MYAAC') or die('Direct access not allowed!');
|
|
$title = 'Mailer';
|
|
|
|
csrfProtect();
|
|
|
|
if (!hasFlag(FLAG_CONTENT_MAILER) && !superAdmin()) {
|
|
echo 'Access denied.';
|
|
return;
|
|
}
|
|
|
|
if (!setting('core.mail_enabled')) {
|
|
echo 'Mail support disabled in config.';
|
|
return;
|
|
}
|
|
|
|
$mail_to = isset($_POST['mail_to']) ? stripslashes(trim($_POST['mail_to'])) : null;
|
|
$mail_subject = isset($_POST['mail_subject']) ? stripslashes($_POST['mail_subject']) : null;
|
|
$mail_content = isset($_POST['mail_content']) ? stripslashes($_POST['mail_content']) : null;
|
|
|
|
if (isset($_POST['submit'])) {
|
|
if (empty($mail_subject)) {
|
|
warning('Please enter subject of the message.');
|
|
}
|
|
|
|
if (empty($mail_content)) {
|
|
warning('Please enter content of the message.');
|
|
}
|
|
}
|
|
if (!empty($mail_to)) {
|
|
if(!Validator::email($mail_to)) {
|
|
warning('E-Mail is invalid.');
|
|
}
|
|
else {
|
|
if (!empty($mail_content) && !empty($mail_subject)) {
|
|
if (_mail($mail_to, $mail_subject, $mail_content)) {
|
|
success("Successfully mailed <strong>$mail_to</strong>");
|
|
}
|
|
else {
|
|
error("Error while sending mail to <strong>$mail_to</strong>. More info can be found in system/logs/mailer-error.log");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!empty($mail_content) && !empty($mail_subject) && empty($mail_to)) {
|
|
$success = 0;
|
|
$failed = 0;
|
|
|
|
$add = '';
|
|
if (setting('core.account_mail_verify')) {
|
|
note('Note: Sending only to users with verified E-Mail.');
|
|
$add = ' AND `email_verified` = 1';
|
|
}
|
|
|
|
$query = $db->query('SELECT `email` FROM `accounts` WHERE `email` != ""' . $add);
|
|
foreach ($query as $email) {
|
|
if (_mail($email['email'], $mail_subject, $mail_content)) {
|
|
$success++;
|
|
}
|
|
else {
|
|
$failed++;
|
|
echo '<br />';
|
|
error('An error occorred while sending email to <b>' . $email['email'] . '</b>. For Admin: More info can be found in system/logs/mailer-error.log');
|
|
}
|
|
}
|
|
|
|
success('Mailing finished.');
|
|
success("$success emails delivered.");
|
|
warning("$failed emails failed.");
|
|
}
|
|
|
|
$twig->display('admin.mailer.html.twig', [
|
|
'mail_to' => $mail_to,
|
|
'mail_subject' => $mail_subject,
|
|
'mail_content' => $mail_content
|
|
]);
|