#!/usr/bin/perl print "Content-type:text/html\n\n"; read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ s/\n/ /g; # strip line breaks $FORM{$name} = $value; } print "Results\n"; print "\n"; print "

Results

\n"; $mailprog = "/usr/sbin/sendmail"; # change email $recipient if necessary # You can safely put an @-sign inside a single-quote string, like # 'kira@metronet.com', or you can escape the @-sign in other strings # by using a backslash. For example, "kira\@metronet.com". $recipient = "hthu\@usa.net"; if ($FORM{'username'} eq "your_name") { &dienice("Please fill out the field for your name."); } open (MAIL, "|$mailprog -t") or &dienice("Can't access $mailprog!\n"); print MAIL "To: $recipient\n"; print MAIL "Subject: Form Data\n\n"; # here you're just printing out all the variables and values, just like # before in the previous script, only the output is to the mail message # rather than the followup HTML page. foreach $key (keys(%FORM)) { print MAIL "$key = $FORM{$key}\n"; } close(MAIL); # write to a data file, rather than emailing # # open(OUTF,">>shsurvey.txt") or &dienice("Couldn't open shsurvey.txt for # writing. Please notify hthu\@usa.net."); # # print OUTF "$FORM{'username'}|$FORM{'fav_char'}|$FORM{'villain'}"; # # %boxes = ("HList" => "Hounds of the Internet", # "BSList" => "Baker Street E-regulars", # "RList" => "Russ-l list"); # # foreach $key (keys %boxes) { # if ($FORM{$key} == 1) { # print "$FORM{username} is a list member of the "; # print "$boxes{$key}
\n"; # } # } # # print OUTF "|$FORM{'comments'}\n"; # close(OUTF); # now print something to the HTML page, usually thanking the person # for filling out the form, and giving them a link back to your homepage print <Form results have been sent

Thank you for submitting your information.


Return to my Experimenting site or to
my Sherlock Holmes tin-box. EndofHTML; sub dienice { ($errmsg) = @_; print "

Error

\n"; print "$errmsg

\n"; print "\n"; exit; } # end of shform.cgi # this cgi is to be used with the form on sherUIcgi.html