#!/usr/bin/perl ####################################################### #-----------------------------------------------------# # BS Form (version 1.3) # #-----------------------------------------------------# # Copyright 1999 Brian Stanback # # # # http://www.stanback.net # #-----------------------------------------------------# # You are free to change this script in any way you # # want, as long as the copyright and this message # # remain intact. I will not be held responsable for # # any damage this script may cause. If you use this # # script I would appreciate a link back to my site # # (stanback.net). Enjoy! :-) # ####################################################### # This is a simple form which will take in a users name, # email, phone number, message, and message subject and # email it to you. It can read from a file and automatically # send it to the user. Script does not require SSI. ######################### # Declare the variables # ######################### $mailprogram = "/usr/lib/sendmail"; # Sendmail $myemail = 'brian@stanback.net'; @required = ('email','subject'); # Required Fields $auto_response = "False"; # Do you want an autoresponse? # True = yes and False = no $auto_response_file = "response.txt"; # File with the message you want to give the user # automatically when (s)he sends the form. ##################################################### # You don't need to change anything below this line # ##################################################### # Parse the form read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ s/\;//g; $value =~ s/\|//g; $value =~ s/\/</g; $FORM{$name} = $value; } $FORM{'email'} =~ s/^([^ ]+) (.*)/$1/g; # Check for all required fields foreach $check(@required) { unless ($FORM{$check}) { print "Content-type: text/html\n\n"; print "\n\nMissing Information\n\n"; print "\n
\n"; print "

Missing Information


\n"; print "Sorry, please fill out the $check field. Go back and try again.\n
\n"; print "\n\n"; exit; } } # Check the users email if ($FORM{'myemail'}) { unless ($FORM{'myemail'} =~ /\w+@\w+.\w+/) { print "Content-type: text/html\n\n"; print "\n\nBad E-mail\n\n"; print "\n
\n"; print "

Bad E-mail


\nThe e-mail address that the user of this \n"; print "script entered is invalid. Please contact them.\n"; print "
\n\n"; exit; } } # Check the senders email if ($FORM{'email'}) { unless ($FORM{'email'} =~ /\w+@\w+.\w+/) { print "Content-type: text/html\n\n"; print "\n\nBad E-mail\n\n"; print "\n
\n"; print "

Bad E-mail


\nThe e-mail address that you've\n"; print "entered, $FORM{'email'}, is invalid. How would I ever contact you? Go back and try again.\n"; print "
\n\n"; exit; } } # Send me the email open (MAIL,"|$mailprogram -t"); print MAIL "To: $myemail\n"; print MAIL "From: <$FORM{'email'}> $FORM{'name'}\n"; print MAIL "Subject: $FORM{'subject'}\n\n"; foreach $line ($FORM{'info'}) { print MAIL "$line"; } print MAIL "\n\n--\n$FORM{'name'}\n"; print MAIL "$FORM{'phone'}"; close MAIL; # Send user an autoresponse. if ($auto_response =~ /True/i && $FORM{'email'}) { open (MAIL,"|$mailprogram -t"); print MAIL "To: $FORM{'name'} <$FORM{'email'}>\n"; print MAIL "From: $myemail\n"; print MAIL "Subject: Re: $FORM{'subject'}\n\n"; print MAIL "This is an autoresponse notifying you that your email has indeed been received. I shall be contacting you shotly.\n\n"; foreach $line ($FORM{'info'}) { print MAIL ">$line"; } close MAIL; } # Print thank you message to the user. print "Content-type: text/html\n\n"; print "\n\nThank you!\n\n"; print "\n"; print "

Thank you!


\nI have received your information \n"; print "and will get back to you asap.\n"; if ($auto_response =~ /True/i && $FORM{'email'}) { print "You should receive an autoresponse shortly.

\n"; } print "

\n\n";