#!/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


-- Page 1 -- Page 2 -- Page 3 -- Page 4 --
"; # close printing to html response &Html_Trailer; # # subroutines after this point # # the html_header header and trailer subroutines are lifted straight # out of the Managing Internet Information Resources O'Reilly book # Page 365 (with a bit of modification to take a title _and_ headline). sub Html_Header { $Document_Title = $_[0]; $Document_Header = $_[1]; print "Content-type: text/html\n\n"; print "\n"; print "\n"; print "$Document_Title\n"; print "\n"; print "\n"; print "

$Document_Header

\n"; print "

\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; }