#!/usr/bin/perl # mailform.pl -- Read the contents of a form and mail it to the email # address set in the variable $email. To use, the HTML FORM ACTION tag # should contain the URL of this program. For instance: # #
# Name: # Email address: # Check here: # #
# # If the user fills out the form as follows: # # Name: Matt Mahoney # Email address: matmahoney@aol.com # Check here: X # [Press here] # # Then the following line of input is sent to this program # # myname=Matt+Mahoney&email=matmahoney%40aol.com&ischecked=on # # This is translated into a more readable format by breaking into # lines on the "&", replacing "+" with space, and "%NN" (%00 through # %FF) with hexadecimal character NN, like this: # # myname=Matt Mahoney # email=matmahoney@aol.com # ischecked=on # # The program then mails this data to email@hostname.com and prints # an HTML confirmation to the user. The confirmation shows the # data and the address to which it was sent. # Get email address $email="mmahoney@cs.fit.edu"; # Get input from form, save in $_ $_=; # Translate $_ into readable form: + to space, & to newline, %NN to char NN s/\+/ /g; s/&/\n/g; s/%(\w\w)/sprintf("%c", hex($1))/ge; # Mail the form if ($email && open(F, "|sendmail $email")) { print F "Subject: Automated request\n$_\n.\n"; close F; } # Print a confirmation print "Content-Type: text/html Form Mailed Thank you for your request. The following information has been forwarded to $email

$_

Return to main menu ";