Main Page Content
Quick And Dirty Form Processor
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:
/full/path/to/cgi-bin/
Change to the "full path" to your cgi dir.
$varSendFormDataTo = "user1\@Foo.com";
Change Foo.com to your domain and user1 to the target user. Make sure you have \@
and not a 'bare' @
. $varSentFrom = "WebServer\@Foo.com";
If you want to send to more than one user, add a comma and the new name@foo.com. $varSubject = "Web Form Comments";
Change the Subject variable to what you want displayed on the email. $varJumpToWebPage = "http://www.foo.com/index.html";
This is the page you are redirected to - can be any valid page anywhere on the internet.Verify that sendmail is in your/usr/sbin/
directory. The quickest way is to type'whereis sendmail'Three - Save your file in your cgi directory. chmod 755 <file name>.
Four - Get cgi-lib.pl from http://cgi-lib.stanford.edu/cgi-lib/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.
#!/usr/bin/perl## Quick & Dirty Form Processing....BEGIN {unshift @INC, '/full/path/to/cgi-bin/' }; require "cgi-lib.pl";##
## User Set Variables$varSendFormDataTo = "user1\@Foo.com";$varSentFrom = "WebServer\@Foo.com";$varSubject = "Web Form Comments";$varJumpToWebPage = "http://www.foo.com";##
## System Set Variables$varSendMail = "/usr/sbin/sendmail -t -n";$today = `date`;$returnvalue=&ReadParse(\%input);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
";
exit;