xref: /plugin/smtp/admin.php (revision ee5c02056e482f4a07fb4b075ec45c4dfd3de0e8)
1<?php
2
3use dokuwiki\Extension\AdminPlugin;
4use dokuwiki\Form\Form;
5
6/**
7 * Swiftmail Plugin
8 *
9 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
10 * @author     Andreas Gohr <andi@splitbrain.org>
11 */
12
13class admin_plugin_smtp extends AdminPlugin
14{
15    /**
16     * return sort order for position in admin menu
17     */
18    public function getMenuSort()
19    {
20        return 200;
21    }
22
23    /**
24     * handle user request
25     */
26    public function handle()
27    {
28        global $INPUT;
29        global $conf;
30        if (!$INPUT->bool('send')) return;
31
32        // make sure debugging is on;
33        $conf['plugin']['smtp']['debug'] = 1;
34
35        // send a mail
36        $mail = new Mailer();
37        if ($INPUT->str('to')) $mail->to($INPUT->str('to'));
38        if ($INPUT->str('cc')) $mail->cc($INPUT->str('cc'));
39        if ($INPUT->str('bcc')) $mail->bcc($INPUT->str('bcc'));
40        $mail->subject('DokuWiki says hello');
41        $mail->setBody("Hi @USER@\n\nThis is a test from @DOKUWIKIURL@");
42
43        $ok = $mail->send();
44
45        // check result
46        if ($ok) {
47            msg('Message was sent. SMTP seems to work.', 1);
48        } else {
49            msg('Message wasn\'t sent. SMTP seems not to work properly.', -1);
50        }
51    }
52
53    /**
54     * Output HTML form
55     */
56    public function html()
57    {
58        global $INPUT;
59        global $conf;
60
61        echo $this->locale_xhtml('intro');
62
63        if (!$conf['mailfrom']) msg($this->getLang('nofrom'), -1);
64
65
66        $form = new Form();
67        $form->addClass('plugin_smtp_admin');
68        $form->addFieldsetOpen('Testmail');
69        $form->setHiddenField('send', 1);
70        $form->addTextInput('to', 'To:')->val($INPUT->str('to'));
71        $form->addTextInput('cc', 'Cc:')->val($INPUT->str('cc'));
72        $form->addTextInput('bcc', 'Bcc:')->val($INPUT->str('bcc'));
73        $form->addButton('submit', 'Send Email')->attr('type', 'submit');
74        $form->addFieldsetClose();
75
76        echo $form->toHTML();
77    }
78}
79