#!/usr/local/bin/perl -wT use strict; # ensure all fatals go to browser during debugging and setup # *don't* uncomment these 5 lines on production code for security #BEGIN { # $|=1; # print "Content-type: text/html\n\n"; # use CGI::Carp('fatalsToBrowser'); #} $|=1; print "Content-type: text/html\n\n"; # print a header # make the environment safer delete @ENV{qw(IFS CDPATH ENV BASH_ENV)}; $ENV{'PATH'} = '/usr/bin:/usr/local/bin'; # CGI.pm stuff use CGI; $CGI::DISABLE_UPLOADS = 1; # disable uploads $CGI::POST_MAX = 1024; # limit post to 1kB my $query = new CGI; # get a CGI object # a few config vars my $mail_prog = '/usr/lib/sendmail'; my $our_email = 'us@us.com'; my $us = "Just another Perl Hacker"; # get our form input from our CGI.pm object my $formid= $query->param('formid') || ''; my $name = $query->param('name') || ''; my $email = $query->param('email') || ''; my $fax = $query->param('fax') || ''; # logic to decide what to do if ($formid eq "myform") { if ($name and ($email or $fax)) { &Send_Mail; &Thanks; } else { &Error("Invalid input, use Back button and try again") } } else { &Show_Form; # first time dispay form } exit; ################# SUBROUTINES ################### sub Send_Mail { open ('MAIL', "|$mail_prog -t") or die "Can't open mail $!\n"; print MAIL <<" TEXT"; To: $our_email Reply-to: $our_email From: $us Subject: Form Input Name: $name Email: $email FAX: $fax TEXT close MAIL; } sub Thanks { print <<" HTML";

Thanks for using my form HTML } sub Error { my $message = shift; print <<" HTML";

$message HTML } sub Show_Form { print <<" HTML"; Form

Name
Email
FAX
HTML }