#!/usr/local/bin/perl # Credits: Dr. William R. Somsky for his # insights as well as the code snippet that formats the outgoing # email. $recipient = "eriley\@u.washington.edu"; $subject = "new form submission"; $response = "submitted.shtml"; use CGI qw(:cgi); $data = new CGI; # split "_order" field on commas @order = split(/,/,$data->param('_order')); # stop if no order defined &cry("no defined field order") unless defined(@order); # send the email message open(MAIL, "| /usr/lib/sendmail -n -oi -t"); print MAIL "To: $recipient\n"; print MAIL "Subject: $subject\n"; print MAIL "X-Remote-Host: $ENV{REMOTE_HOST}\n"; print MAIL "\n"; foreach $name (@order){ $label = "$name:"; @values = $data->param($name); # array for multi-valued fields foreach $value (@values) { my @lines = split ("\n", $value) ; foreach (@lines) { $_ =~ s/\r$// ; } printf MAIL "%-15s%s", $label, length $label <= 15 ? "\t" : "\n\t\t" ; print MAIL join("\n\t\t", @lines), "\n" ; } } close (MAIL); # redirect to response page $uri = $ENV{SCRIPT_NAME}; $uri =~ s|[^/]*$||; $url = "http://" . $ENV{SERVER_NAME} . $uri . $response; print $data->redirect($url); #done exit; # a little subroutine to handle errors sub cry { my($message) = @_; # print initial response header print $data->header; print "This CGI program failed to process your submission.\n"; print "The problem seems to be: $message.\n"; print "Please contact the owner."; exit; }