xref: /plugin/smtp/admin.php (revision ecc6033d478e204cc39f32c32c02fc45a1eb3f8d)
14dc22474SAndreas Gohr<?php
24dc22474SAndreas Gohr/**
33ff87f82SAndreas Gohr * Swiftmail Plugin
44dc22474SAndreas Gohr *
53ff87f82SAndreas 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    /**
143ff87f82SAndreas Gohr     * return sort order for position in admin menu
154dc22474SAndreas Gohr     */
163ff87f82SAndreas Gohr    function getMenuSort() {
173ff87f82SAndreas Gohr        return 200;
184dc22474SAndreas Gohr    }
194dc22474SAndreas Gohr
204dc22474SAndreas Gohr    /**
213ff87f82SAndreas Gohr     * handle user request
224dc22474SAndreas Gohr     */
233ff87f82SAndreas Gohr    function handle() {
243ff87f82SAndreas Gohr        global $INPUT;
253ff87f82SAndreas Gohr        global $conf;
263ff87f82SAndreas Gohr        if(!$INPUT->bool('send')) return;
273ff87f82SAndreas Gohr
283ff87f82SAndreas Gohr        // make sure debugging is on;
293ff87f82SAndreas Gohr        $conf['plugin']['smtp']['debug'] = 1;
303ff87f82SAndreas Gohr
313ff87f82SAndreas Gohr        // send a mail
323ff87f82SAndreas Gohr        $mail = new Mailer();
333ff87f82SAndreas Gohr        if($INPUT->str('to')) $mail->to($INPUT->str('to'));
34*ecc6033dSYurii K        if($INPUT->str('cc')) $mail->cc($INPUT->str('cc'));
35*ecc6033dSYurii K        if($INPUT->str('bcc')) $mail->bcc($INPUT->str('bcc'));
363ff87f82SAndreas Gohr        $mail->subject('DokuWiki says hello');
373ff87f82SAndreas Gohr        $mail->setBody("Hi @USER@\n\nThis is a test from @DOKUWIKIURL@");
383ff87f82SAndreas Gohr        $ok = $mail->send();
393ff87f82SAndreas Gohr
403ff87f82SAndreas Gohr        // check result
413ff87f82SAndreas Gohr        if($ok){
423ff87f82SAndreas Gohr            msg('Message was sent. SMTP seems to work.',1);
433ff87f82SAndreas Gohr        }else{
443ff87f82SAndreas Gohr            msg('Message wasn\'t sent. SMTP seems not to work properly.',-1);
453ff87f82SAndreas Gohr        }
464dc22474SAndreas Gohr    }
474dc22474SAndreas Gohr
484dc22474SAndreas Gohr    /**
493ff87f82SAndreas Gohr     * Output HTML form
504dc22474SAndreas Gohr     */
513ff87f82SAndreas Gohr    function html() {
523ff87f82SAndreas Gohr        global $INPUT;
533ff87f82SAndreas Gohr        global $conf;
543ff87f82SAndreas Gohr
553ff87f82SAndreas Gohr        echo $this->locale_xhtml('intro');
563ff87f82SAndreas Gohr
573ff87f82SAndreas Gohr        if(!$conf['mailfrom']) msg($this->getLang('nofrom'),-1);
583ff87f82SAndreas Gohr
593ff87f82SAndreas Gohr
603ff87f82SAndreas Gohr        $form = new Doku_Form(array());
613ff87f82SAndreas Gohr        $form->startFieldset('Testmail');
623ff87f82SAndreas Gohr        $form->addHidden('send', 1);
633ff87f82SAndreas Gohr        $form->addElement(form_makeField('text', 'to', $INPUT->str('to'), 'To:', '', 'block'));
643ff87f82SAndreas Gohr        $form->addElement(form_makeField('text', 'cc', $INPUT->str('cc'), 'Cc:', '', 'block'));
653ff87f82SAndreas Gohr        $form->addElement(form_makeField('text', 'bcc', $INPUT->str('bcc'), 'Bcc:', '', 'block'));
663ff87f82SAndreas Gohr        $form->addElement(form_makeButton('submit', '', 'Send Email'));
673ff87f82SAndreas Gohr
683ff87f82SAndreas Gohr        $form->printForm();
694dc22474SAndreas Gohr    }
704dc22474SAndreas Gohr
714dc22474SAndreas Gohr}
72