summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2021-03-03 14:00:18 +0300
committerAndrew Dolgov <[email protected]>2021-03-03 14:00:18 +0300
commit0730128a97a46054099b59554e891cee99829eaa (patch)
tree8e77a0f91c4854dd6e658c97284a27c4588b1c2c
parentdbda996a7a04ce96803e045dfaf27d1c577c3f4e (diff)
add a send test email button to prefs/system
-rw-r--r--classes/mailer.php13
-rwxr-xr-xclasses/pluginhost.php2
-rw-r--r--classes/pref/system.php49
3 files changed, 59 insertions, 5 deletions
diff --git a/classes/mailer.php b/classes/mailer.php
index 968caf54a..564338f69 100644
--- a/classes/mailer.php
+++ b/classes/mailer.php
@@ -1,8 +1,6 @@
<?php
class Mailer {
- // TODO: support HTML mail (i.e. MIME messages)
-
- private $last_error = "Unable to send mail: check local configuration.";
+ private $last_error = "";
function mail($params) {
@@ -39,11 +37,18 @@ class Mailer {
$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) {
$this->last_error = $message;
+ user_error("Error sending mail: $message", E_USER_WARNING);
}
function error() {
diff --git a/classes/pluginhost.php b/classes/pluginhost.php
index e96bbaa7c..bd0e9f4d8 100755
--- a/classes/pluginhost.php
+++ b/classes/pluginhost.php
@@ -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_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_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_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)
diff --git a/classes/pref/system.php b/classes/pref/system.php
index 85635e753..e58765c49 100644
--- a/classes/pref/system.php
+++ b/classes/pref/system.php
@@ -14,6 +14,20 @@ class Pref_System extends Handler_Administrative {
$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() {
ob_start();
phpinfo();
@@ -161,6 +175,41 @@ class Pref_System extends Handler_Administrative {
?>
</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') ?>'>
<script type='dojo/method' event='onSelected' args='evt'>
if (this.domNode.querySelector('.loading'))