add a send test email button to prefs/system
This commit is contained in:
parent
dbda996a7a
commit
0730128a97
|
@ -1,8 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
class Mailer {
|
class Mailer {
|
||||||
// TODO: support HTML mail (i.e. MIME messages)
|
private $last_error = "";
|
||||||
|
|
||||||
private $last_error = "Unable to send mail: check local configuration.";
|
|
||||||
|
|
||||||
function mail($params) {
|
function mail($params) {
|
||||||
|
|
||||||
|
@ -39,11 +37,18 @@ class Mailer {
|
||||||
|
|
||||||
$headers = [ "From: $from_combined", "Content-Type: text/plain; charset=UTF-8" ];
|
$headers = [ "From: $from_combined", "Content-Type: text/plain; charset=UTF-8" ];
|
||||||
|
|
||||||
return mail($to_combined, $subject, $message, implode("\r\n", array_merge($headers, $additional_headers)));
|
$rc = mail($to_combined, $subject, $message, implode("\r\n", array_merge($headers, $additional_headers)));
|
||||||
|
|
||||||
|
if (!$rc) {
|
||||||
|
$this->set_error(error_get_last()['message']);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
function set_error($message) {
|
function set_error($message) {
|
||||||
$this->last_error = $message;
|
$this->last_error = $message;
|
||||||
|
user_error("Error sending mail: $message", E_USER_WARNING);
|
||||||
}
|
}
|
||||||
|
|
||||||
function error() {
|
function error() {
|
||||||
|
|
|
@ -61,7 +61,7 @@ class PluginHost {
|
||||||
const HOOK_FEED_BASIC_INFO = "hook_feed_basic_info"; // hook_feed_basic_info($basic_info, $fetch_url, $owner_uid, $feed_id, $auth_login, $auth_pass) (byref)
|
const HOOK_FEED_BASIC_INFO = "hook_feed_basic_info"; // hook_feed_basic_info($basic_info, $fetch_url, $owner_uid, $feed_id, $auth_login, $auth_pass) (byref)
|
||||||
const HOOK_SEND_LOCAL_FILE = "hook_send_local_file"; // hook_send_local_file($filename)
|
const HOOK_SEND_LOCAL_FILE = "hook_send_local_file"; // hook_send_local_file($filename)
|
||||||
const HOOK_UNSUBSCRIBE_FEED = "hook_unsubscribe_feed"; // hook_unsubscribe_feed($feed_id, $owner_uid)
|
const HOOK_UNSUBSCRIBE_FEED = "hook_unsubscribe_feed"; // hook_unsubscribe_feed($feed_id, $owner_uid)
|
||||||
const HOOK_SEND_MAIL = "hook_send_mail"; // hook_send_mail($mailer, $params)
|
const HOOK_SEND_MAIL = "hook_send_mail"; // hook_send_mail(Mailer $mailer, $params)
|
||||||
const HOOK_FILTER_TRIGGERED = "hook_filter_triggered"; // hook_filter_triggered($feed_id, $owner_uid, $article, $matched_filters, $matched_rules, $article_filters)
|
const HOOK_FILTER_TRIGGERED = "hook_filter_triggered"; // hook_filter_triggered($feed_id, $owner_uid, $article, $matched_filters, $matched_rules, $article_filters)
|
||||||
const HOOK_GET_FULL_TEXT = "hook_get_full_text"; // hook_get_full_text($url)
|
const HOOK_GET_FULL_TEXT = "hook_get_full_text"; // hook_get_full_text($url)
|
||||||
const HOOK_ARTICLE_IMAGE = "hook_article_image"; // hook_article_image($enclosures, $content, $site_url)
|
const HOOK_ARTICLE_IMAGE = "hook_article_image"; // hook_article_image($enclosures, $content, $site_url)
|
||||||
|
|
|
@ -14,6 +14,20 @@ class Pref_System extends Handler_Administrative {
|
||||||
$this->pdo->query("DELETE FROM ttrss_error_log");
|
$this->pdo->query("DELETE FROM ttrss_error_log");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sendTestEmail() {
|
||||||
|
$mail_address = clean($_REQUEST["mail_address"]);
|
||||||
|
|
||||||
|
$mailer = new Mailer();
|
||||||
|
|
||||||
|
$rc = $mailer->mail(["to_name" => "",
|
||||||
|
"to_address" => $mail_address,
|
||||||
|
"subject" => __("Test message from tt-rss"),
|
||||||
|
"message" => ("This message confirms that tt-rss can send outgoing mail.")
|
||||||
|
]);
|
||||||
|
|
||||||
|
print json_encode(['rc' => $rc, 'error' => $mailer->error()]);
|
||||||
|
}
|
||||||
|
|
||||||
function getphpinfo() {
|
function getphpinfo() {
|
||||||
ob_start();
|
ob_start();
|
||||||
phpinfo();
|
phpinfo();
|
||||||
|
@ -161,6 +175,41 @@ class Pref_System extends Handler_Administrative {
|
||||||
?>
|
?>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div dojoType='dijit.layout.AccordionPane' style='padding : 0' title='<i class="material-icons">mail</i> <?= __('Mail Configuration') ?>'>
|
||||||
|
<div dojoType="dijit.layout.ContentPane">
|
||||||
|
|
||||||
|
<form dojoType="dijit.form.Form">
|
||||||
|
<script type="dojo/method" event="onSubmit" args="evt">
|
||||||
|
evt.preventDefault();
|
||||||
|
if (this.validate()) {
|
||||||
|
xhr.json("backend.php", this.getValues(), (reply) => {
|
||||||
|
const msg = App.byId("mail-test-result");
|
||||||
|
|
||||||
|
if (reply.rc) {
|
||||||
|
msg.innerHTML = __("Mail sent.");
|
||||||
|
msg.className = 'alert alert-success';
|
||||||
|
} else {
|
||||||
|
msg.innerHTML = reply.error;
|
||||||
|
msg.className = 'alert alert-danger';
|
||||||
|
}
|
||||||
|
|
||||||
|
msg.show();
|
||||||
|
})
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<?= \Controls\hidden_tag("op", "pref-system") ?>
|
||||||
|
<?= \Controls\hidden_tag("method", "sendTestEmail") ?>
|
||||||
|
|
||||||
|
<fieldset>
|
||||||
|
<label><?= __("To:") ?></label>
|
||||||
|
<?= \Controls\input_tag("mail_address", "", "text", ['required' => 1]) ?>
|
||||||
|
<?= \Controls\submit_tag(__("Send test email")) ?>
|
||||||
|
<span style="display: none; margin-left : 10px" class="alert alert-error" id="mail-test-result">...</span>
|
||||||
|
</fieldset>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div dojoType='dijit.layout.AccordionPane' title='<i class="material-icons">info</i> <?= __('PHP Information') ?>'>
|
<div dojoType='dijit.layout.AccordionPane' title='<i class="material-icons">info</i> <?= __('PHP Information') ?>'>
|
||||||
<script type='dojo/method' event='onSelected' args='evt'>
|
<script type='dojo/method' event='onSelected' args='evt'>
|
||||||
if (this.domNode.querySelector('.loading'))
|
if (this.domNode.querySelector('.loading'))
|
||||||
|
|
Loading…
Reference in New Issue