It's better when it's simple

User Tools

Site Tools


Translations of this page?:

Learn about DokuWiki

Advanced Use

Corporate Use

Our Community

Follow us on Facebook, Twitter and other social networks.

Our Privacy Policy


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 <> or just 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->subject('A test mail');
$mail->setBody("Hi\n\nthis is your test mail");

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'  => ''
// the HTML placeholder input that differ from the text ones
$hrep = array(
    'WEB'  => '<a href="">DokuWiki</a>'
// standard mail sending as seen above
$mail = new Mailer();
$mail->to('Some Guy <>');
$mail->subject('A test mail');
$mail->setBody($text, null, $trep, $hrep);

setBody() parameters changed?

According to setBody documentation, the order of the parameters has changed to

function setBody($text, $textrep = null, $htmlrep = null, $html = null, $wrap = true)

So, in the above example the call of setBody should be

$mail->setBody($text, $trep, $hrep);

Dralli72 2018-03-03 01:01

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.

devel/mail.txt · Last modified: 2018-03-03 01:08 by Dralli72