#!/usr/local/bin/perl # ############################### ## mailform ################################ # This processes the input from "formfill.cgi" or "formfill.shtml" # # This is a demo of what you can do with a form, it # requires certain fields to be there, as is explained below. # Feel free to modify it as required, but be advised that # modifying it on a PC may put in extra carriage returns # that will have to be removed when it is re-uploaded. # keys from formfill.cgi: # name (required), # from, # country, # email (required), # comment(required). # caller (identifies the person using this script) ################################################################# # Get info from form and parse it # (this is a standard way of handling input from forms) # the next line shows how to get the input from a GET # $raw_data = $ENV{'QUERY_STRING'}; # # This script uses method=post, so here's how that is done read(STDIN, $raw_data, $ENV{CONTENT_LENGTH}); # for POST # the following does the parsing $items = split('&', $raw_data); for ($i = 0; $i < $items; $i++) { ($key,$value) = split('=', $_[$i]); $value =~ tr/+/ /; $value =~ s/%(..)/pack("C", hex($1))/eg; $data{"$key"} = $value; } # In order to find the name for mailing, the "caler" value is used $yourname = $data{caler}; # mail program opened with a pipe - note that it is set to send to the # "To:" and "Cc:" addresses by using the "-t" $mailprog = "/usr/lib/sendmail -t"; # check for "valid" e-mail address - at least x@y.z $data{'email'}= "" if ($data{'email'} !~ /.+\@.+\..+/); # what the above says is "make the field blank if it doesn't contain at least one # character, an @ sign, a character, a "." and one trailing character." # It will fail the next test, and put out the "Oops" page asking for a vaild # e-mail address. ######################################################## # # Check for required fields, if not, put out "Oops" page # # This demo requires that the name, e-mail address, and # comments fields be filled in. # # The next line says, in effect "if name and e-mail and # comment are there, process it, otherwise skip to "Oops" # page output, where the missing ones will be flagged." # ( "&&" means "and") if ($data{name} && $data{email} && $data{comment}){ # # name, email, and comments are there, so do ################# MAILING STUFF ########################### $maildone = ".\n"; # end of mail input open(MAIL, "| $mailprog") || die "Can't open mailprog $mailprog, stopped"; # output mail lines print MAIL "From: $data{email}\n"; # who from print MAIL "To: $yourname\@best.com\n"; # to you print MAIL "Subject: Form Filled In By $data{name}\n"; print MAIL " \n"; print MAIL "Used name: $data{name}\n"; print MAIL "Actually from $ENV{REMOTE_ADDR}\n"; # IP address print MAIL "Said logged in from: $data{from}, $data{country}\n"; print MAIL "Email: $data{email}\n"; print MAIL "\n"; print MAIL "Form said:\n"; $dataout = $data{comment}; # set up to format data write MAIL; # write formatted data print MAIL "End of Form\n"; # last line of form print MAIL $maildone; # send a "." and return to mail close(MAIL) || die "mail pipe exited $?"; ########################## # Display "Thank You" page print < Thank You

Thank you for the entry, $data{name}.


NEWPAGE #################################################### # This does the processing for missing required fields on the form # The line will print if the entry is missing, that's what the # "if (!....)" part checks for - the "!" means "no" or "not", so # print " - your name.
" if (!$data{name}); # is saying "print the line '- your name' if there was no name" # } else { print "Content-type: text/html\n\n"; print "Oops..."; print "

Oops!...

"; print "Looks like you hit the wrong key!.
"; print "If you would like to submit an entry, I need:
"; print " - your name.
" if (!$data{name}); print " - your e-mail address, in the form \"name\@host\"
" if (!$data{email}); print " for example: myname\@myprovider.com
" if (!$data{email}); print " - your comments
" if (!$data{comment}); print "Go back and try again...

Thanks...


"; } # End of "else" block # All done, get out exit; ################## format statements ########################## # The format statement is better explained in the Perl book # with the llama on the cover. ####### NOTE: The following are all on one line each!!!!!!! # # This will put out as much as the person input (note the "~~" # on the second format line) format MAIL = ~^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $dataout ~~^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $dataout . ########################end of script################