CGI::ContactForm - Perl extension for generating a web contact form


    use lib '/path/to/lib';  (For the case this module, or any
                              module it's dependent on, is installed
                              in a local library.)
    use CGI::ContactForm;

    contactform (
        recname        => 'John Smith',              \
        recmail        => '',    } Compulsory
        smtp           => '',         /

        styleurl       => '/style/ContactForm.css',  \
        returnlinktext => 'Back',                     } Optional
        returnlinkurl  => '/some/url',               /


This module generates a contact form for the web when the routine contactform() is called from a CGI script. The CGI script shall consist of just a few lines of code like in the example under SYNOPSIS above. The arguments are passed to the module as a list of key/value pairs.

CGI::ContactForm sends a well formated (plain text format=flowed in accordance with RFC 2646) email message, with the sender's address in the From: header, and the sender gets a bcc copy. If the email address stated by the sender is invalid, the failure message is sent to the recipient address, through which you know that you don't need to bother with a reply, at least not to that address...


Installation with Makefile.PL

Type the following:

    perl Makefile.PL
    make test
    make install

Manual Installation

  • Download and extract the distribution file.

  • Designate a directory as your local library for Perl modules, for instance

  • Create the directory /cgi-bin/lib/CGI, and upload to that directory.

If Mail::Sender and Text::Flowed (see DEPENDENCIES below) need to be installed manually, you shall create /cgi-bin/lib/Mail and /cgi-bin/lib/Text and upload respective to those directories.


CGI::ContactForm requires these modules, available at CPAN:


It also requires direct access to an SMTP server.


An example CGI script ( and a style sheet (ContactForm.css) are included in the distribution. Note that the style sheet typically needs to be located somewhere outside the cgi-bin.


v0.4 (Feb 9, 2003)

Error alert message added. Also ContactForm.css was modified for this reason.

Test script included in the distribution.

v0.3 (Feb 7, 2003)

Check of email syntax modified (hopefully now closer to RFC 822).

Better structured code.

v0.2 (Feb 5, 2003)

Referer check in order to only accept data input from the generated form.

Improved email validation.

v0.1 (Feb 3, 2003)

Initial release.


The latest version of CGI::ContactForm is available at: and


  Copyright © 2003 Gunnar Hjalmarsson

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 126:

Non-ASCII character seen before =encoding in '©'. Assuming ISO8859-1