MailForm

Basic setup

To just get a basic form that can be used to send mail, simply install the Cookbook:PmForm module and then add the following lines to a local customization file (e.g., local/config.php):

    $EnablePmFormMailSubjectEncode = 1; # for international sites
    include_once("$FarmD/cookbook/pmform.php");
    $PmForm['maildemo'] = 'mailto=mailform-demo@pobox.com form=#mailform fmt=#mailpost';

(for multiple addresses, use quotes around all of them and commas in between)

    $PmForm['maildemo'] = 'mailto="mailform-demo@pobox.com, anotheraddress@samplemail.com, a@a.com" form=#mailform fmt=#mailpost';

Then, wherever you want a form to appear to send mail to pmichaud@pobox.com, use the directive

    (:pmform maildemo:)

The "maildemo" portion of this directive is called the target, and it indicates that the mail is to be sent according to the options given by the corresponding entry in the $PmForm array. Within the 'maildemo' entry, "mailto=" specifies the recipient address for the email, "form=" specifies the form template to be displayed by the (:pmform maildemo:) directive, and "fmt=" specifies the template for the email to be sent.

Example pmform directive

(:pmform maildemo:)

Your address:
Subject:
Message:

Captcha

The above mailform actually works -- see mailform.txt to see what the mail looked like when it was received.

Customized templates

The "form=" and "fmt=" options specify pages or page sections to be used for displaying the form and formatting the form output. If only a section identifier is given (e.g., "form=#mailform"), then PmForm looks in the Site.PmFormTemplates and Site.LocalTemplates pages for the template.

The "form=" option specifies the template to use for the form displayed by the (:pmform:) directive. Usually this is built using PmWiki's (:input:) directives.

[[#mailform]]
(:template defaults successpage='' :)
(:input pmform target={$$target} successpage={$$successpage} :)
(:input default request=1:)
(:messages:)
||width='' 
||$[Your address]: ||(:input text from size=30:) ||
||$[Subject]:      ||(:input text subject size=30:) ||
$[Message]:\\
(:input textarea text rows=8 cols=60:)\\
{$Captcha} (:input captcha:) \\
(:input submit name=post value='$[Send]':)
(:input end:)
[[#mailformend]]

The (:input pmform:) line specifies that this is a form to be handled by the PmForm module, and that it's to process the form according to whatever target was given by the (:pmform:) directive. Here, the form contains three fields to be filled in by the sender: the sender's address ("from"), the message subject ("subject"), and the text of the message itself ("text").

The "fmt=" option specifies the template to use for sending the email based on the inputs provided by the form. For example, the #mailform template that comes with PmForm contains:

[[#mailpost]]
(:template require from errmsg="$[Missing 'from' address]" :)
(:template require subject errmsg="$[Missing message subject]" :)
(:template require text errmsg="$[Message text required]" :) 
(:template require if="captcha" errmsg="$[Captcha required]" :)

{$$text}

==========
Sent via PmForm at {$$PageUrl}
[[#mailpostend]] 

The (:template require:) directives are used to specify certain conditions that must be met before the mail can be set. For the above, this template requires that the "from", "subject", and "text" fields supplied by the sender are non-empty (and specifies error messages to display if they aren't).

The remainder of the template specifies the body of the email to be sent by PmForm. The {$$text} field is replaced by the message text coming from the input form, and {$$PageUrl} is substituted with the url to the current page. (The "from" and "subject" fields are automatically handled by PmForm.:)

The {$$...} template substitutions may contain any arbitrary page variables or input fields coming from the form.


Comments

Is it possible to put the "form=" and "fmt=" parameters directly into the (:pmform:) directive? (so that modifying the local configuration file is not necessary)

Blues May 23, 2007, at 03:20 AM

I just took a quick look at the code, and it doesn't seem to support that. However, it does seem that the target name can be the name of a text field on the page. (I'm not sure if thats the source page or the target page though), so that one should be able to do something like:

 (:pmform foo:)
 ...
 foo: mailto=mailform-demo@pobox.com form=#mailform fmt=#mailpost

and have that work.

StirlingWestrup September 13, 2007, at 09:12 AΜ
Define email in LocalTemplates page
After messing around, adapting the config file with PmFormPageFmt, allowed me to define the target in the LocalTemplates page.
$PmFormPageFmt = 'Site.LocalTemplates';
Damien December 11, 2009, at 02:08 AM

To provide some very basic email validity testing (which is better than none), change line 151 of pmform.php from

    $errors = PmFormMail($pagename, $msgtmpl, $opt, $safe_opt);

to

    if (strpos($opt['from'],'@')) $errors = PmFormMail($pagename, $msgtmpl, $opt, $safe_opt);
    else $errors = "Please enter a valid email address.";

Ben Stallings December 08, 2008, at 07:33 PM


I (think I) followed the PmForm. instructions, beside of that I didn't create my own lib directory (files are hosted in /wikilib.d/ and /wiki.d/) - and I've omitted the Captcha install, setup and relevant form fields. As we are using PmForm in our Uniserver (XAMPP lite) Cookbook:Standalone Intranet Enterprise Wiki, we don't need Spam protection. (Update 2017-12-16 22:26 - Captcha installed, but it still doesn't work. John Doe is to blame)

After setting up several Mail forms: Everything is there, but no Mails are being sent. Here's my config.php

    $PmForm['webmaster'] = 'subject="E-Mail von '.$WikiTitle.'" mailto=mroth@trade-service.eu form=#wemaform fmt=#wemapost from=wiki@jacob-boehme.de'; 

Uniserver/msmtp/sendmail.log

Dec 17 13:08:45 host=smtp.live.com tls=on auth=on user=john.doe123@hotmail.co.uk from=john.doe123@hotmail.co.uk 
recipients=mroth@trade-service.eu smtpstatus=535 smtpmsg='535 5.0.0 Authentication Failed' 
errormsg='authentication failed (method PLAIN)' exitcode=EX_NOPERM

Do I have to modify php.ini (sendmail_from = no value), anything else? Thanks much for your time and effort, and please excuse my lack of programmer skills! Jazzvox 2017-12-16 22:26

 0: 00.00 00.00 config start
 1: 00.01 00.01 config end
 2: 00.06 MarkupToHTML begin
 3: 00.06 MarkupToHTML begin
 4: 00.09 MarkupToHTML end
 5: 00.23 ReadApprovedUrls SiteAdmin.ApprovedUrls begin
 6: 00.25 ReadApprovedUrls SiteAdmin.ApprovedUrls end
 7: 00.25 MarkupToHTML end
 8: 00.26 MarkupToHTML begin
 9: 00.32 MarkupToHTML end
10: 00.32 MarkupToHTML begin
11: 00.33 MarkupToHTML end
12: 00.34 now