Skip to page content or Skip to Accesskey List.


Main Page Content

Quick And Dirty Form Processor

Rated 3.89 (Ratings: 0)

Want more?

  • More articles in Code
Picture of AnthonyB

Anthony Baratta

Member info

User since: 10 Jul 1999

Articles written: 12

Here is a very simple cgi script to send the form

output to the target mail boxes:

One - cut and paste the code below into "notepad"

Two - edit the following lines:


Change to the "full path" to your cgi dir.

  $varSendFormDataTo = "user1\";

Change to your domain and user1 to the target user.

Make sure you have \@ and not a 'bare' @.

  $varSentFrom = "WebServer\";

If you want to send to more than one user, add a comma and

the new

  $varSubject = "Web Form Comments";

Change the Subject variable to what you want displayed on the email.

  $varJumpToWebPage = "";

This is the page you are redirected to - can be

any valid page anywhere on the internet.

Verify that sendmail is in your


directory. The quickest way is to type

'whereis sendmail'

Three - Save your file in your cgi directory.

  chmod 755 <file name>.

Four - Get from

Save in your cgi-bin directory.

Five - Number your form elements. e.g. add

a #- to the front of each name (FullName

becomes 1-FullName, Email become 2-Email).

The program expect numbers and splits on

the first '-'. This allows you to number

the form elements in the order you want them

to appear in the email.

Six - Don't forget to set your action

to "/cgi-bin/qd-form.cgi" and remove any

form encoding types you have set.

Good Luck.



# Quick & Dirty Form Processing....

BEGIN {unshift @INC, '/full/path/to/cgi-bin/' };

require "";


## User Set Variables

$varSendFormDataTo = "user1\";

$varSentFrom = "WebServer\";

$varSubject = "Web Form Comments";

$varJumpToWebPage = "";


## System Set Variables

$varSendMail = "/usr/sbin/sendmail -t -n";

$today = `date`;


open (MAIL, "| $varSendMail") || die "cannot open mail program";

print MAIL "To: $varSendFormDataTo


print MAIL "From: $varSentFrom


print MAIL "Subject: $varSubject


print MAIL "$today


foreach $var(sort keys %input) {

if (lc($var) eq "submit") {next;}

$varTrimmed = splut(/-/,$var,2);

print MAIL "$varTrimmed -- $input{$var}



print MAIL "


close(MAIL) || die "mail pipe exited $?";

print "Location: $varJumpToWebPage



Mutated into a life-size Dilbert doll, Anthony spends the days wedged into his replica of Cardinal Fang's Comfy Chair coding solutions to the most thorny of internet software problems.

The access keys for this page are: ALT (Control on a Mac) plus: is an all-volunteer resource for web developers made up of a discussion list, a browser archive, and member-submitted articles. This article is the property of its author, please do not redistribute or use elsewhere without checking with the author.