This is an old revision of the document!
Table of Contents
Handling E-Mails in DokuWiki
DokuWiki contains a wrapper class around PHP's mail function that takes care of the proper encoding of headers and body and also implements sending multipart mails (eg. with HTML body or attachements)
Please refer to the Mailer class documentation for implementation details.
All strings are expected to be valid UTF-8 strings. Email addresses should be given in the form Real Name <mail@example.com>
or just mail@example.com
. Multiple addresses can be passed comma separated.
Sending Mail
Sending a mail is simple. Here's the most basic call:
$mail = new Mailer(); $mail->to('Some Guy <mail@example.com>'); $mail->subject('A test mail'); $mail->setBody("Hi\n\nthis is your test mail"); $mail->send();
DokuWiki does send Text and HTML mails by default. When you only supply a the first parameter to setBody()
, the class will create the HTML body automatically.
Using Replacements
The setBody()
function accepts key-value pairs as 3rd and 4th parameter to handle placeholder replacements. Supplying HTML replacements is optional. The HTML replacements will be merged with the text replacements, so you only need to specify those that differ from plain text.
// the text with some placeholders, usually loaded from a language file $text = 'Hello @NAME@, check out @WEB@!'; // the plain text placeholder input $trep = array( 'NAME' => 'Some Guy', 'WEB' => 'http://www.dokuwiki.org' ); // the HTML placeholder input that differ from the text ones $hrep = array( 'WEB' => '<a href="http://www.dokuwiki.org">DokuWiki</a>' ); // standard mail sending as seen above $mail = new Mailer(); $mail->to('Some Guy <mail@example.com>'); $mail->subject('A test mail'); $mail->setBody($text, $trep, $hrep); $mail->send();
Checking for valid E-Mail
Use the simple utility function mail_isvalid to check if a given address is a valid email address. The function makes use of the php-email-address-validation library.