mirror of
https://github.com/slawkens/myaac.git
synced 2025-04-26 17:29:21 +02:00
Add option to send mail to account with Mailer
"Send Mail" link next to Email input in account editor
This commit is contained in:
parent
62b485abf9
commit
611d6f505d
@ -353,8 +353,8 @@ else if (isset($_REQUEST['search'])) {
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<div class="col-12 col-sm-12 col-lg-6">
|
||||
<label for="email">Email:</label>
|
||||
<input type="text" class="form-control" id="email" name="email" autocomplete="off" maxlength="20" value="<?php echo $account->getEMail(); ?>"/>
|
||||
<label for="email">Email:</label><?php echo (config('mail_enabled') ? ' (<a href="' . ADMIN_URL . '?p=mailer&mail_to=' . $account->getEMail() . '">Send Mail</a>)' : ''); ?>
|
||||
<input type="text" class="form-control" id="email" name="email" autocomplete="off" value="<?php echo $account->getEMail(); ?>"/>
|
||||
</div>
|
||||
<?php if ($hasCoinsColumn): ?>
|
||||
<div class="col-12 col-sm-12 col-lg-6">
|
||||
|
@ -15,55 +15,69 @@ if (!hasFlag(FLAG_CONTENT_MAILER) && !superAdmin()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$config['mail_enabled']) {
|
||||
if (!config('mail_enabled')) {
|
||||
echo 'Mail support disabled.';
|
||||
return;
|
||||
}
|
||||
|
||||
$mail_content = isset($_POST['mail_content']) ? stripslashes($_POST['mail_content']) : NULL;
|
||||
$mail_subject = isset($_POST['mail_subject']) ? stripslashes($_POST['mail_subject']) : NULL;
|
||||
$preview = isset($_REQUEST['preview']);
|
||||
$mail_to = isset($_REQUEST['mail_to']) ? stripslashes(trim($_REQUEST['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;
|
||||
|
||||
$preview_done = false;
|
||||
if ($preview) {
|
||||
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)) {
|
||||
$preview_done = _mail($account_logged->getCustomField('email'), $mail_subject, $mail_content);
|
||||
|
||||
if (!$preview_done)
|
||||
error('Error while sending preview mail. More info can be found in system/logs/mailer-error.log');
|
||||
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;
|
||||
|
||||
$twig->display('admin.mailer.html.twig', array(
|
||||
'mail_subject' => $mail_subject,
|
||||
'mail_content' => $mail_content,
|
||||
'preview_done' => $preview_done
|
||||
));
|
||||
|
||||
if (empty($mail_content) || empty($mail_subject) || $preview)
|
||||
return;
|
||||
|
||||
$success = 0;
|
||||
$failed = 0;
|
||||
|
||||
$add = '';
|
||||
if ($config['account_mail_verify']) {
|
||||
$add = '';
|
||||
if (config('account_mail_verify')) {
|
||||
note('Note: Sending only to users with verified E-Mail.');
|
||||
$add = ' AND ' . $db->fieldName('email_verified') . ' = 1';
|
||||
}
|
||||
$add = ' AND `email_verified` = 1';
|
||||
}
|
||||
|
||||
$query = $db->query('SELECT ' . $db->fieldName('email') . ' FROM ' . $db->tableName('accounts') . ' WHERE ' . $db->fieldName('email') . ' != ""' . $add);
|
||||
foreach ($query as $email) {
|
||||
if (_mail($email['email'], $mail_subject, $mail_content))
|
||||
$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.");
|
||||
}
|
||||
|
||||
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
|
||||
]);
|
||||
|
@ -18,21 +18,22 @@
|
||||
</div>
|
||||
<form method="post">
|
||||
<div class="card-body">
|
||||
<div class="form-group row">
|
||||
<label for="mail_to">To: (enter email, or leave empty to all)</label>
|
||||
<input class="form-control" type="text" id="mail_to" name="mail_to" value="{{ mail_to }}"/>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<label for="mail_subject">Subject:</label>
|
||||
<input class="form-control" type="text" id="mail_subject" name="mail_subject"
|
||||
value="{{ mail_subject }}" size="30" maxlength="30"/>
|
||||
<input class="form-control" type="text" id="mail_subject" name="mail_subject" value="{{ mail_subject }}" maxlength="30"/>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<label for="mail_content" class="control-label">Content:</label>
|
||||
<textarea id="mail_content" name="mail_content" style="width: 100%" class="tinymce">{{ mail_content }}</textarea>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<input type="checkbox" name="preview" id="preview" value="1"/><label for="category">Just send test email to me (preview)</label>{% if preview_done %} - <b>Done.</b>{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
<button type="submit" class="btn btn-info"><i class="fas fa-share"></i> Send</button>
|
||||
<button type="submit" name="submit" class="btn btn-info"><i class="fas fa-share"></i> Send</button>
|
||||
<a href="{{ constant('ADMIN_URL') }}?p=mailer" class="btn btn-danger float-right">Cancel</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user