home *** CD-ROM | disk | FTP | other *** search
/ Web Designer 98 (Professional) / WebDesigner 1.0.iso / tutorials / tutorial / formmail.txt < prev    next >
Encoding:
Text File  |  1997-06-15  |  3.4 KB  |  108 lines

  1. #!/usr/bin/perl
  2. ######################
  3. # General Mail Form To Work With Any Fields
  4. # Created 6/9/95                Last Modified 6/11/95
  5. # Version 1.0
  6.  
  7. # Define Variables
  8. $mailprog = '/usr/sbin/sendmail';
  9. $date = `/bin/date`; chop ($date);
  10.  
  11. ######################
  12. # Necessary Fields in HTML Form:   
  13. # recipient = specifies who mail is sent to
  14. # username = specifies the remote users email address for replies
  15. # realname = specifies the remote users real identity
  16. # subject = specifies what you want the subject of your mail to be
  17.  
  18. # Print the Initial Output Heading
  19. print "Content-type: text/html\n\n";
  20.  
  21. # Get the input
  22. read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
  23.  
  24. # Split the name-value pairs
  25. @pairs = split(/&/, $buffer);
  26.  
  27. foreach $pair (@pairs)
  28. {
  29.     ($name, $value) = split(/=/, $pair);
  30.  
  31.     # Un-Webify plus signs and %-encoding
  32.     $value =~ tr/+/ /;
  33.     $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  34.     $name =~ tr/+/ /;
  35.     $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  36.  
  37.     # Stop people from using subshells to execute commands
  38.     # Not a big deal when using sendmail, but very important
  39.     # when using UCB mail (aka mailx).
  40.     # $value =~ s/~!/ ~!/g;
  41.  
  42.     # Uncomment for debugging purposes
  43.     # print "Setting $name to $value<P>";
  44.  
  45.     $FORM{$name} = $value;
  46. }
  47.  
  48. # Print Return HTML
  49. print "<html><head><title>Thank You</title></head>\n";
  50. print "<body><h1>Thank You For Filling Out This Form</h1>\n";
  51. print "Thank you for taking the time to fill out our my form.";
  52. print "Below is what you submitted.<hr>\n";
  53.  
  54.  
  55. # Open The Mail
  56. open (MAIL, "|$mailprog $FORM{'recipient'}") || die "Can't open $mailprog!\n";
  57. print MAIL "From: $FORM{'username'} ($FORM{'realname'})\n";
  58. print MAIL "Reply-To: $FORM{'username'} ($FORM{'realname'})\n";
  59. print MAIL "To: $FORM{'recipient'}\n";
  60. print MAIL "Subject: $FORM{'subject'}\n\n";
  61. print MAIL "Below is the result of your feedback form.  It was submitted by $FORM{'realname'} ($FORM{'username'} on $date\n";
  62. print MAIL "--------------------------------------------------------------\n";
  63. foreach $pair (@pairs)
  64. {
  65.     ($name, $value) = split(/=/, $pair);
  66.  
  67.     # Un-Webify plus signs and %-encoding
  68.     $value =~ tr/+/ /;
  69.     $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  70.     $name =~ tr/+/ /;
  71.     $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  72.  
  73.     # Stop people from using subshells to execute commands
  74.     # Not a big deal when using sendmail, but very important
  75.     # when using UCB mail (aka mailx).
  76.     # $value =~ s/~!/ ~!/g;
  77.  
  78.     # Uncomment for debugging purposes
  79.     # print "Setting $name to $value<P>";
  80.  
  81.     $FORM{$name} = $value;
  82.  
  83. # Print the MAIL for each name value pair
  84.   print MAIL "$name:  $value\n";
  85.   print MAIL "____________________________________________\n\n";
  86.  
  87. # Print the Return HTML for each name value pair.
  88.   print "$name = $value<hr>\n";
  89. }
  90. close (MAIL);
  91.  
  92. print "</body></html>";
  93.  
  94. # open a message to the remote client
  95.   open (MAIL, "|$mailprog $FORM{'username'}") || die "Can't open $mailprog!\n";
  96.   print MAIL "To: $FORM{'username'} ($FORM{'realname'})\n";
  97.   print MAIL "Reply-To: $FORM{'recipient'}\n";
  98.   print MAIL "From: $FORM{'recipient'}\n";
  99.   print MAIL "Subject: $FORM{'subject'}\n\n";
  100.  
  101.   # write out a customized response to the mail message
  102.   print MAIL "Thanks for filling out my comics voting form.";
  103.   print MAIL " I will post the results soon. Tell all your friends about it, too.";
  104.   print MAIL " Peace!";
  105.   
  106.   # close the message
  107.   close (MAIL);
  108.