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