Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions modules/system/controllers/Settings.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<?php namespace System\Controllers;

use Mail;
use Lang;
use Flash;
use Config;
use Request;
use Backend;
use BackendMenu;
use System\Classes\SettingsManager;
use System\Behaviors\SettingsModel;
use Backend\Classes\Controller;
use ApplicationException;
use Exception;
Expand Down Expand Up @@ -118,6 +120,27 @@ public function update_onSave($author, $plugin, $code = null)
}
}

/**
* Saves the current configuration and sends a test email to the current user
*/
public function update_onTest(string $author, string $plugin, $code = null)
{
try {
$this->update_onSave($author, $plugin, $code);

SettingsModel::clearInternalCache();

Mail::raw(Lang::get('system::lang.settings.test_content'), function ($msg) {
$msg->to([$this->user->email => $this->user->full_name]);
$msg->subject(Lang::get('system::lang.settings.test_subject'));
});

Flash::success(Lang::get('system::lang.mail_templates.test_success'));
} catch (Exception $ex) {
Flash::error($ex->getMessage());
}
}

public function update_onResetDefault($author, $plugin, $code = null)
{
$item = $this->findSettingItem($author, $plugin, $code);
Expand Down
12 changes: 11 additions & 1 deletion modules/system/controllers/settings/update.htm
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,21 @@
data-request-confirm="<?= e(trans('backend::lang.form.action_confirm')) ?>">
<?= e(trans('backend::lang.form.reset_default')) ?>
</button>

<button
type="button"
class="btn btn-info pull-right"
data-request="onTest"
data-request-data="redirect:0"
data-load-indicator="<?= e(trans('system::lang.mail_templates.sending')) ?>"
data-request-confirm="<?= e(trans('system::lang.mail_templates.test_confirm', [ 'email' => e(BackendAuth::getUser()->email)])) ?>">
<?= e(trans('system::lang.mail_templates.test_send')) ?>
</button>
</div>
</div>
<?= Form::close() ?>

<?php else: ?>
<p class="flash-message static error"><?= e(trans($this->fatalError)) ?></p>
<p><a href="<?= $parentLink ?>" class="btn btn-default"><?= e(trans('system::lang.settings.return')) ?></a></p>
<?php endif ?>
<?php endif ?>
2 changes: 2 additions & 0 deletions modules/system/lang/en/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@
'not_found' => 'Unable to find the specified settings.',
'missing_model' => 'The settings page is missing a Model definition.',
'update_success' => ':name settings updated',
'test_subject' => 'Mail driver test',
'test_content' => 'This is a test email to confirm that the provided mail settings work.',
'return' => 'Return to system settings',
'search' => 'Search',
],
Expand Down