#! /usr/local/bin/perl #---------------------------------------------------------------------- # Form-mail.pl, by Reuven M. Lerner (reuven@the-tech.mit.edu). # This package is Copyright 1994 by The Tech. # Packaged Modified to mail any form to you by Matt Wright # (mattw@alpha.pr1.k12.co.us) # Modified to include default comment form by David Efflandt # (efflandt@xnet.com) # Form-mail is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; either version 2, or (at your option) any # later version. # Form-mail is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # See the GNU General Public License for more details. # For a copy of the GNU General Public License, write to the Free # Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. # ------------------------------------------------------------ ###################### # General Form Mail Script To Work With Any Fields # For any form using POST method or built-in comment/request form. # Created 11/19/95 Last Modified 12/31/96 # Define Variables for your system $mailprog = '/usr/lib/sendmail'; $recipient = 'yourname@yournet.com'; $nickname = 'Bob'; # nickname or company name $homepage = '/~yourname/index.html'; ###################### # Necessary Fields in HTML Form: # recipient = dummy hidden form variable to detect hacking (not required) # username = the remote users email address for replies (required) # realname = the remote users real identity # subject = subject line of email response # Get remote host $ip_address = $ENV{'REMOTE_ADDR'}; @numbers = split(/\./, $ip_address); $ip_number = pack("C4", @numbers); ($host) = (gethostbyaddr($ip_number, 2))[0]; # Create default comment form on GET &make_form unless ($ENV{'REQUEST_METHOD'} eq "POST"); # Get the input read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); # Split the name-value pairs @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; $name =~ tr/+/ /; $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $FORM{$name} = $value; } if ($FORM{'redirect'}) { print "Location: $FORM{'redirect'}\n\n"; } else { # Print Return HTML &begin_html("Thank You"); print "

Thank You

\n"; print "Thank you for taking the time to fill out my feedback form.
"; print "Below is what you submitted to $nickname.


\n"; } # Open The Mail open(MAIL, "|$mailprog -t") || die "Can't open $mailprog: $!\n"; print MAIL <\n $ENV{'HTTP_USER_AGENT'} EOM print MAIL "$host " if $host; print MAIL "$ENV{'REMOTE_ADDR'}\n", ('-' x 60), "\n"; foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $name =~ tr/+/ /; $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; # Print the MAIL for each name value pair if (length($value) > 65) {$value = "\n\n".$value;} (print MAIL "$name: $value\n\n") if $value; # Print Return HTML for each name value pair. (print "$name: $value
\n") if ($value&&!$FORM{'redirect'}); } close (MAIL); &end_html unless ($FORM{'redirect'}); ### Subroutines #subroutine begin_html(title) sub begin_html { local ($title) = @_; print "Content-type: text/html\n\n"; print "$title\n" } #subroutine end_html sub end_html { local($nicks) = $nickname."'s"; $referer = $FORM{'referer'} if ($FORM{'referer'}); print qq(

$recipient\n); print qq(

[ $nicks Home Page ); print qq(| Previous Page ) if ($referer); print "]\n"; } #subroutine make_form sub make_form { # Get page that called form $referer = $ENV{'HTTP_REFERER'}; &begin_html("Comments for $nickname"); print <

Comment/Request Form

Please enter your comments or request for $nickname below and press the submit button. Check that your full Email address is valid if expecting a response.


Name:

Email:

Location:

Subject:

Comments:

*

NEW_FORM &end_html; exit; }