#!/usr/bin/perl ######################################################################################## # Description: This program takes a forms input and sends an email to specified person # based on the email's subject(category) and sends a confirmation email # to the original sender and redirects user to specied page upon completion. # It allows you to use the same email program to email different feedback # categories to different areas. It also hides # # Notes: This program requires the form use "POST" method. # The form MUST have a "Subject" field(capital S) that specifies the category of email # The form MUST have a "UserEmail" field(capital U & E) that specifies the users email address # The form MUST have a "Username" field(capital U) that specifies the users name # Copyright WMoore.ca http://www.wmoore.ca - Walter Moore Last updated 1998-11-24 ######################################################################################## #------------------------------------------------------------- # Where do you want to Redirect them to once completed # Make a nice Thank you page and use it here. #------------------------------------------------------------- $Redirect_to = 'http://www.wmoore.ca/thankyou.htm'; #------------------------------------------------------------- # Set the default email address for user response to automatic confirmation. # This MUST be set. Used as response address for client. # NOTICE THE "\" IS REQUIRED IN EMAIL BEFORE "@" OR CGI WILL FAIL #------------------------------------------------------------- $DefaultMail = 'walter\@wmoore.ca'; #------------------------------------------------------------- # Set variables for email address and Category name for ease of update # This has to change. Use email addresses of people you want. # Category must equal the forms "subject" field value exactly. # NOTICE THE "\" IS REQUIRED IN EMAIL BEFORE "@" OR CGI WILL FAIL #------------------------------------------------------------- $Category1 = 'Web Site'; $Category1Mail = 'somebody1\@wmoore.ca'; $Category2 = 'Company'; $Category2Mail = 'somebody2\@wmoore.ca'; $Category3 = 'Products'; $Category3Mail = 'somebody3\@wmoore.ca'; $Category4 = 'Store'; $Category4Mail = 'somebody4\@wmoore.ca'; $Category5 = 'Employee'; $Category5Mail = 'somebody5\@wmoore.ca'; #------------------------------------------------------------- # The 6th Category MUST be "Other" or "(Other)" for code to work! # NOTICE THE "\" IS REQUIRED IN EMAIL ADDRESS OR CGI WILL FAIL #------------------------------------------------------------- $Category6 = '(Other)'; $Category6Mail = 'somebody6\@wmoore.ca'; ######################################################################################## # # NO MORE CHANGES REQUIRED. # ######################################################################################## $mailprog = '/usr/sbin/sendmail'; 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; $name =~ tr/+/ /; $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $FORM{$name} = $value; } print "Location: $Redirect_to\n\n"; $Contact = $DefaultMail; if ($FORM{'Subject'} eq "$Category1") { $Contact = $Category1Mail; } elsif ($FORM{'Subject'} eq "$Category2") { $Contact = $Category2Mail; } elsif ($FORM{'Subject'} eq "$Category3") { $Contact = $Category3Mail; } elsif ($FORM{'Subject'} eq "$Category4") { $Contact = $Category4Mail; } elsif ($FORM{'Subject'} eq "$Category5") { $Contact = $Category5Mail; } elsif ($FORM{'Subject'} eq "$Category6") { $Contact = $Category6Mail; } #------------------------------------------------------------- # send to internal person. #------------------------------------------------------------- open(MAIL, "|$mailprog -t") || die "Can't open Server Mail Program!\n Sorry, Unable to send Feedback."; print MAIL "To: $Contact \n"; print MAIL "From: $FORM{'UserEmail'} \n"; print MAIL "Subject: Feedback Response\n\n"; print MAIL "Hello,\n\n"; print MAIL "A visitor has just submitted Feedback\n"; print MAIL "related to $FORM{'Subject'} on the Web Feedback form.\n\n"; print MAIL "While there is currently no policy regarding response time\n"; print MAIL "please respond quickly to reasonable questions.\n\n"; print MAIL "Thank you.\n"; print MAIL "---------------------------------------------------------\n\n"; foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $name =~ tr/+/ /; $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $FORM{$name} = $value; print MAIL "$name: $value\n"; } close (MAIL); #------------------------------------------------------------- # send to external person that submitted form. #------------------------------------------------------------- open(MAIL, "|$mailprog -t") || die "Can't open Server Mail Program!\n Sorry, Unable to send Feedback."; print MAIL "To: $FORM{'UserEmail'}\n"; print MAIL "From: $DefaultMail\n"; print MAIL "Subject: Thank you for your feedback\n\n"; print MAIL "Hello $FORM{'Username'},\n\n"; print MAIL "Thank you for providing feedback.\n\n"; print MAIL "We value your input and appreciate you taking the time to provide it.\n\n"; print MAIL "Due to the volume of feedback we receive we can't promise \n"; print MAIL "a response. However, your feedback will be forwarded to the \n"; print MAIL "appropriate department for review and consideration.\n\n"; close (MAIL);