home *** CD-ROM | disk | FTP | other *** search
/ PC World 1997 November / PCWorld_1997-11_cd.bin / komunike / utility / webweav / _SETUP.1 / formmail.cgi < prev    next >
Text File  |  1997-07-15  |  3KB  |  106 lines

  1. #!/usr/bin/perl
  2.  
  3. #----------------------------------------------------------------------
  4. # Form-mail.pl, by Reuven M. Lerner (reuven@the-tech.mit.edu).
  5. # This package is Copyright 1994 by The Tech.
  6. # Packaged Modified to mail any form to you by Matt Wright (mattw@misha.net)
  7.    
  8. # FormMail is free software; you can redistribute it and/or modify it
  9. # under the terms of the GNU General Public License as published by the
  10. # Free Software Foundation; either version 2, or (at your option) any
  11. # later version.
  12.    
  13. # FormMail is distributed in the hope that it will be useful, but
  14. # WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16. # General Public License for more details.
  17.  
  18. # Write the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  19. # If you would like to obtain a copy of the GNU GPL.
  20. # ------------------------------------------------------------
  21.  
  22. ####################################################
  23. # FormMail
  24. # Created by Matt Wright
  25. # Created 6/9/95                Last Modified 9/23/95
  26. # Version 1.2
  27. # I can be reach at:        mattw@misha.net
  28. # Scripts Archive at:        http://www.worldwidemart.com/scripts/
  29.  
  30. # Define Variables
  31. $mailprog = '/usr/lib/sendmail';
  32. $date = `/usr/bin/date`; chop($date);
  33.  
  34. # Get the input
  35. read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
  36.  
  37. # Split the name-value pairs
  38. @pairs = split(/&/, $buffer);
  39.  
  40. foreach $pair (@pairs){
  41.    ($name, $value) = split(/=/, $pair);
  42.  
  43.    $value =~ tr/+/ /;
  44.    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  45.    $name =~ tr/+/ /;
  46.    $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  47.           
  48.    $FORM{$name} = $value;
  49. }
  50.  
  51. if ($FORM{'redirect'}) {
  52.    print "Location: $FORM{'redirect'}\n\n";
  53. }
  54. else {
  55.    # Print Return HTML
  56.    print "Content-type: text/html\n\n";
  57.    print "<html><head><title>Thank You</title></head>\n";
  58.    print "<body><h1>Thank You For Filling Out This Form</h1>\n";
  59.    print "Thank you for taking the time to fill out my feedback form. ";
  60.    print "Below is what you submitted to $FORM{'recipient'} on ";
  61.    print "$date<hr>\n";
  62. }
  63.  
  64. # Open The Mail
  65. open(MAIL, "|$mailprog -t") || die "Can't open $mailprog!\n";
  66. print MAIL "To: $FORM{'recipient'}\n";
  67. print MAIL "From: $FORM{'email'} ($FORM{'realname'})\n";
  68. if ($FORM{'subject'}) {
  69.    print MAIL "Subject: $FORM{'subject'}\n\n";
  70. }
  71. else {
  72.    print MAIL "Subject: WWW Form Submission\n\n";
  73. }
  74. print MAIL "Below is the result of your feedback form.  It was\n";
  75. print MAIL "submitted by $FORM{'realname'} ($FORM{'email'}) on $date\n";
  76. print MAIL "---------------------------------------------------------\n";
  77.  
  78. foreach $pair (@pairs) {
  79.    ($name, $value) = split(/=/, $pair);
  80.  
  81.    $value =~ tr/+/ /;
  82.    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  83.    $name =~ tr/+/ /;
  84.    $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  85.  
  86.    $FORM{$name} = $value;
  87.    unless ($name eq 'recipient' || $name eq 'subject' || $name eq 'email' || $name eq 'realname' || $name eq 'redirect') {
  88.       # Print the MAIL for each name value pair
  89.       if ($value ne "") {
  90.          print MAIL "$name:  $value\n\n";
  91.       }
  92.  
  93.       unless ($FORM{'redirect'}) {
  94.          if ($value ne "") {
  95.             print "$name = $value<br>\n";
  96.          }
  97.       }
  98.    }
  99. }
  100. close (MAIL);
  101.  
  102. unless ($FORM{'redirect'}) {
  103.    print "</body></html>";
  104. }
  105.  
  106.