UPDATE: This patch can also be applied as-is to the 2007-06-26b version. I used WebFaction's one-click DokuWiki installation script to install a new DokuWiki installation and was able to apply the patch. There are two caveats however:
webapps directory. That means I had to search/replace the “dokuwiki” paths in the patch to “webapps/dokuwiki”$body = mail_quotedprintable_encode($body);
right before the line:
$smtp = Mail::factory('smtp', array(
after the patch is applied.
It would be nice if I had time to redo the patch to make this easier for you. Sorry about that.
This patch requires that your PHP installation have the PEAR Mail package already installed. Apparently this is quite common, and it was already installed here at WebFaction.
The patch works on versions 2007-06-26b and 2006-11-06. See note above for a bug that was introduced in the patch and how to fix it.
patch.txt. Put it at the same level as your dokuwiki-2006-11-06 folder.patch -Np0 < patch.txtpatch is, see Patch (Unix). There may be help there for Windows users. Mac users can access patch from the Terminal command line.inc/mail.php, while there are other patches to make the Configuration Manager work with the new configuration settings.smtp host: set this to the hostname of the SMTP server, e.g. mailx.webfaction.comsmtp auth: select the check box to use SMTP authenticationsmtp from: the From address to use for outgoing mail 1)smtp user: username for SMTP authenticationsmtp pass: password for SMTP authenticationsmtp host blank, DokuWiki will operate as it did pre-patch. In other words, it will use PHP's mail() function and will not use SMTP.Save. This patch works for me, but it probably isn't fully complete for inclusion in DokuWiki's tree. Mostly it's missing the following features:
comment in the code, if SMTP is activated, extra headers and mail params that DokuWiki code may be setting are ignored. As far as I can tell, these are not currently in use, so it's no big deal today. But it's not clean code to fail silently like that.$smtp→send() call in mail.php, but I forgot to put one there.//use $from, if $to is empty. if ($to=='') { $to=$from; }
Copy this code into a file on your server and follow the instructions above.
diff -Nbaur -X diff-exclude.txt dokuwiki-2006-11-06/conf/dokuwiki.php dokuwiki/conf/dokuwiki.php --- dokuwiki-2006-11-06/conf/dokuwiki.php 2006-11-06 09:32:07.000000000 -1000 +++ dokuwiki/conf/dokuwiki.php 2006-12-15 19:18:06.000000000 -1000 @@ -130,3 +130,9 @@ $conf['ftp']['pass'] = 'password'; $conf['ftp']['root'] = '/home/user/htdocs'; +/* new conf settings for smtp */ +$conf['smtp']['host'] = ''; // if blank will use regular PHP mail() +$conf['smtp']['auth'] = 0; +$conf['smtp']['from'] = ''; +$conf['smtp']['user'] = ''; +$conf['smtp']['pass'] = ''; diff -Nbaur -X diff-exclude.txt dokuwiki-2006-11-06/inc/mail.php dokuwiki/inc/mail.php --- dokuwiki-2006-11-06/inc/mail.php 2006-11-06 09:32:08.000000000 -1000 +++ dokuwiki/inc/mail.php 2006-12-15 19:31:16.000000000 -1000 @@ -14,6 +14,7 @@ if(!defined('MAILHEADER_EOL')) define('MAILHEADER_EOL',"\n"); #define('MAILHEADER_ASCIIONLY',1); + /** * UTF-8 autoencoding replacement for PHPs mail function * @@ -34,6 +35,9 @@ * @see mail() */ function mail_send($to, $subject, $body, $from='', $cc='', $bcc='', $headers=null, $params=null){ + global $conf; + + if(defined('MAILHEADER_ASCIIONLY')){ $subject = utf8_deaccent($subject); $subject = utf8_strip($subject); @@ -47,6 +51,8 @@ // No named recipients for To: in Windows (see FS#652) $usenames = (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') ? false : true; + if ($conf['smtp']['host'] == '') { + // old version of mail_send, using php's mail() $to = mail_encode_address($to,'',$usenames); $header .= mail_encode_address($from,'From'); $header .= mail_encode_address($cc,'Cc'); @@ -64,6 +70,44 @@ }else{ return @mail($to,$subject,$body,$header,$params); } + } + else { + // use Mail's SMTP facility + // FIXME ignores incoming $headers and $params arguments!! + require_once "Mail.php"; + + // see if From is overriden from settings + if ($conf['smtp']['from'] != '') + $from = $conf['smtp']['from']; + + $from = mail_encode_address($from, ''); + $to = mail_encode_address($to, '', $usenames); + $cc = mail_encode_address($cc, ''); + $bcc = mail_encode_address($bcc, ''); + + $headers = array( + 'From' => $from, + 'Subject' => $subject, + 'Cc' => $cc, + 'Bcc' => $bcc, + 'MIME-Version' => '1.0', + 'Content-Type' => 'text/plain; charset=UTF-8', + 'Content-Transfer-Encoding' => 'quoted-printable', + ); + + $smtp = Mail::factory('smtp', array( + 'host' => $conf['smtp']['host'], + 'auth' => $conf['smtp']['auth'], + 'username' => $conf['smtp']['user'], + 'password' => $conf['smtp']['pass'], + )); + + $result = $smtp->send($to, $headers, $body); + if (PEAR::isError($result)) + return FALSE; + else + return TRUE; + } } /** diff -Nbaur -X diff-exclude.txt dokuwiki-2006-11-06/lib/plugins/config/settings/config.metadata.php dokuwiki/lib/plugins/config/settings/config.metadata.php --- dokuwiki-2006-11-06/lib/plugins/config/settings/config.metadata.php 2006-11-06 09:32:08.000000000 -1000 +++ dokuwiki/lib/plugins/config/settings/config.metadata.php 2006-12-15 19:17:57.000000000 -1000 @@ -177,3 +177,8 @@ $meta['ftp____pass'] = array('password'); $meta['ftp____root'] = array('string'); +$meta['smtp____host'] = array('string'); +$meta['smtp____auth'] = array('onoff'); +$meta['smtp____from'] = array('string'); +$meta['smtp____user'] = array('string'); +$meta['smtp____pass'] = array('string');