Summary: Provide a web form that sends email to fixed email addresses
Version: 2007-11-10
Prerequisites: pmwiki-2.0.0 or later
Status: stable
Maintainer: Hombre
Discussion: EMailForm-Talk
Categories: FormTools

Questions answered by this recipe

  • Can I create a form that will allow people to contact me via mail without giving my email address away to spammers?
  • Can this form send data using UTF-8 encoding?
  • Can it have some captcha functionality?


The emailform.zipΔ script allows you to place a small web form into a wiki page that sends email to fixed email addresses. It can be modified to send e-mails using utf-8 encoding, and to use a simple but effective SPAM protection. Moreover it can be styled using css and produces xhtml valid code.

Installation and Configuration

To use the recipe, simply unpack it into the directory containing your pmwiki installation. The emailform.php file should go into the cookbook directory, the other files should go into pub/emailform/. The script adds a emailform:xyz markup to your wiki pages. The xyz is a name that you can then associate with an email address in your local customization file (e.g. local/config.php). For example:

    $EnableEMailFormSecurity = true;
    $EMailFormAddresses['Pm'] = '';
    $EMailFormDefaultSender = '';
    $EnableEMailFormUTF8 = false;

This gives the markup emailform:Pm which creates a mailform that will send electronic mail to If the sender leaves the "sender address" field empty, the mail will appear to come from


Required variables

The sender from which the mail is sent if the 'Your address' field in the form was left empty.
An array containing the relation of names and email-addresses (e.g. $EMailFormAddresses['nils'] = '' will let you use mailform:nils in a WikiPage to send a mail to '')

Optional variables for customizing the look and functionality of the form

The HTML code for the form itself. '$1' is replaced with the To:-address identifier.
Text to be prepended to the sender's message.
Text to be appended to the sender's message.
If this is set to 'true' the user will be asked to enter a three-digit code before sending. This variable should be set before the line starting with 'include_once...'.
If this is set to 'true' emails will be sent using utf-8 encoding. This variable should be set after the line starting with 'include_once...'.

Other strings are all internationalized - the default values belong in the 'en' (English) language:

    $XL['en']['MFsuccess'] = 'Message has been sent successfully.';
    $XL['en']['MFfailure'] = 'Message could not be sent.';
    $XL['en']['MFerror']   = 'An error has occurred.';
    $XL['en']['MFwrongcode'] = 'Wrong security code. Are you sure you are human?';
    $XL['en']['Your address:'] = 'From:';

--noe - to be complete ... is it :
    $XL['en']['Your Address:'] = 'Your Address:';
    $XL['en']['Subject:'] = 'Subject:';
    $XL['en']['Message:'] = 'Message:';
    $XL['en']['Send'] = 'Send';

-- and even...

    $XL['en']['Repeat Security Code:'] = 'Repeat Security Code:'


CSS styling

The form can be styled using css. To alter the look of the emailform, simply edit the emailform.css file that should be located in the folder pub/emailform/ of your pmwiki installation.

Older Stuff

The mailform.phpΔ script allows you to place a small web form into a wiki page that sends email to fixed email addresses. It can be modified to send e-mails using utf-8 encoding, and to use a simple but effective SPAM protection. Moreover it can be tyle using css and produces xhml valid code. Mailform.php wont be supported for releases later than v 1.5. The emailform-s.phpΔ script adds a 3-digit confirmation code to reduce spam, similar to CommentBoxPlus, but without the JavaScript. It is based on emailform.php above. Formatting is a bit kludgy. Example on; if the form moves, you can reach it from the site's sidebar.

The old emailform1_2.phpΔ is still available here.

Future planning

  • Rename to emailform.php and completely get rid of mailform.php
  • Ability to specify mail encoding in config.php
  • Add better captcha functionality

Release Notes

29.02.2004First version
29.02.2004A few bug fixes
29.02.2004Changed $MailFormTemplate to $MailFormFmt,
 Added some i18n support with the $MailFormString[] array
01.03.2004Bugfix: Insertion of target name in form was missing
 Use local variable for formatting to enable multiple forms per page (not tested)
16.05.2004Changed regex to mailform:(\w+) in order to allow mailform:nils%comment% to be processed correctly as mailform:nils
06.01.2005Converted for PmWiki v2 (Pm)
08.02.2005Created emailform.php to work with the TellAFriend script.
19.10.2005fixed a minor bug in emailform.php: emailform_2005-10-19.phpΔ
15.12.2006Added confirmation code to reduce spam. emailform-s.phpΔ . Sandy
03.08.2007Version 1.5 of mailform.php and emailform.php Merged xhtml, utf-8 and SPAM catcher to mailform making these obsolete. Hombre
04.08.2007Version 1.5.1: Renamed flags to start with Enable, Updated comments in sourcecode. Hombre
10.11.2007Version 1.5.3: Corrected a mistake in the help file. Hombre

See Also


  • Nils Knappmeier
  • Pm, 2005-01-06, revised for PmWiki v2
  • Susan 2006-03-02, added config.php markup for emailform.php
  • Sandy 2006-12-15, added emailform-s.php for spam prevention
  • Hombre 2007-08-03, merged utf-8, SPAM catcher and xhtml to mailform.php and emailform.php 1.5


See discussion at EMailForm-Talk

User notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.