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