#!/usr/local/bin/perl
###########################################################################
# Program: feedback.cgi
# Version: 1.0 May ??, 1995
# 1.01 May 25, 1995
# Revisions: Added subject to mailing and introduced $Mailto.
# Description: Perl cgi script to take user input and mail it.
# Requirements: perl (4 or 5), a webserver that allows user cgi
# Author: Matt Leonard
# mattl@pobox.com
# http://www.pobox.com/~mattl
# Comments:
# Copyright: This program is copyright 1995-1997 Matt Leonard.
###########################################################################
# variables
$Mailto = "nobody\@nowhere.com";
$Subject = "Feedback about web pages";
# begin program
# get user's input variables
%uservars = &read_query_string;
# mail the feedback to $Mailto
$Msg_To_User = "Mailed your comment to User.";
if (! open(MAIL, "| /bin/mail $Mailto")) {
$Msg_To_User = "Sorry, there's a problem with mail, try again later.";
} else {
print MAIL "Subject: $Subject\n";
print MAIL "\nPerson: $uservars{'name'}\n";
print MAIL "Address: $uservars{'email'}\n";
print MAIL "Comment: $uservars{'comment'}\n";
} # else
close (MAIL);
# build html response page
&Html_Header("Feedback Response", "OK, Got Your Input");
if ($uservars{'name'}) {
print "
YOU:
$uservars{'name'}
"; # close printing to html response
}
if ($uservars{'email'}) {
print "
YOUR ADDRESS:
$uservars{'email'}
"; # close printing to html response
}
if ($uservars{'comment'}) {
print "
YOUR COMMENTS:
$uservars{'comment'}
"; # close printing to html response
}
print "
RESULTS OF SUBMISSION:
$Msg_To_User
\n"; } # Html_Header sub Html_Trailer { print "\n"; print "\n"; } # Html_Trailer # this subroutine is lifted directly out of the Leeds CGI tutorial. # http://agora.leeds.ac.uk/nik/Cgi/start.html # It is very similar to the code in the cgi-lib.pl stuff sub read_query_string { local ($buffer, @pairs, $pair, $name, $value, %FORM); # Read in text $ENV{'REQUEST_METHOD'} =~ tr/a-z/A-Z/; if ($ENV{'REQUEST_METHOD'} eq "POST") { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); } else { # this is a "GET method $buffer = $ENV{'QUERY_STRING'}; } # else @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%(..)/pack("C", hex($1))/eg; $FORM{$name} = $value; } # foreach %FORM; }