Hello, I am building a website using a standard form and perl script that we commonly use, but this one has a special request and I don't know how to handle it because I have very little knowledge of Perl, other than what is in the standard script I have reused for many projects.
I am pasting my code below as it stands now- it currently contains a command for sending the information to me in an email, but I also need two additional emails to be generated once the user fills out the form and presses the submit button. The first should be a confirmation email that will go back to the student confirming receipt of the form, and the should be second a pre-populated email to a professor (using the Instructor Name and Instructor Email filled in on the form by the student).
I'm not sure how to add the instruction to send out these two additional emails, and how to populate with the correct Instructor Name and Student Name. If anyone can shed any light on this I would be really grateful for any pointers.
#!/usr/bin/perl -w
# ***********************
# *** submit.pl ***
# ***********************
# This Perl script handles submissions of registration forms for
# Pearson Arts & Sciences hardside marketing sites
# Updated July 2011
# - - - - - - - - - -
# The basic flow of the script is as follows:
# * Get hidden "company" parameter and define e-mail coordinator and log file.
# * Check user input, send error page if name or email missing
# * Send an email with the form response
# * Display thank you page
print "Content-Type: text/html\n\n";
# Global Variables
# * no need to edit this
$mail_prog = "/usr/lib/sendmail";
# Get library and parse client input
# * no need to edit this
use CGI::Carp qw(fatalsToBrowser);
use CGI;
$request = new CGI;
# Read and check user input
# * edit to include all inputs named in HTML form
# * format: $CHANGETHIS = $request->param('CHANGETHIS');
# * email field required in HTML form (and below) to send form responses from
@option = $request->param("option");
$optionList = join( ', @option );
$studentname = $request->param('studentname');
$instructorname = $request->param('instructorname');
$instructoremail = $request->param('instructoremail');
$affil = $request->param('affil');
$addr = $request->param('addr');
$city = $request->param('city');
$state = $request->param('state');
$zip = $request->param('zip');
$phone = $request->param('phone');
$email = $request->param('email');
$rules = $request->param('rules');
# Define e-mails
# * postEmail - who should receive the form email responses
# * ccEmail - who should be copied on the form email responses
$postEmail = 'emily.wieja@pearson.com';
$ccEmail = 'webmaster@aw.com';
#Put all the required fields in this if statement
# * format: if ($RequiredField1 eq "" || $RequiredField2 eq "")
# * make sure there's no || before the closing parentheses
if (@option eq "" || $optionList eq "" || $studentname eq "" || $instructorname eq "" || $instructoremail eq "" || $affil eq "" || $addr eq "" || $city eq "" || $state eq "" || $zip eq ""|| $phone eq "" || $email eq "" || $rules eq "")
{
# Missing data--send error page
# * need to create HTML error page as part of the site
print <<"!!EOX!!";
<script type="text/javascript" language="JavaScript" >
document.location = "http://vigstage.pearsonhighered.com/dev/awards/alliedhealth/error.html";
</script>
!!EOX!!
}
else {
# Send e-mail form response
# * no need to change first 4 lines
# * Subject: as specified in form copy
# * Following lines are how the emailed response appears
# * no need to change bottom "EOM" line or below
open (MAIL,"|$mail_prog -t") || die "Call to sendmail failed";
print MAIL << "!!EOM!!";
To: $postEmail
CC: $ccEmail
From: $email
Subject: Student Application Allied Health Award 2012
Option 2 link: $optionList
Student's Name: $studentsname
Instructor's Name: $instructorname
Instructor's Email: $instructoremail
Email: $email
College/University: $affil
Student's Address: $addr
City: $city
State: $state
Zip: $zip
Phone: $phone
Student's Email: $email
Have read and downloaded rules: $rules
Submitted from http://vigstage.pearsonhighered.com/dev/awards/alliedhealth/index.html
!!EOM!!
close(MAIL);
# Put your thank you page here
# * need to create HTML thank you page as part of the site
print <<"!!EOX!!";
<script type="text/javascript" language="JavaScript" >
document.location = "http://vigstage.pearsonhighered.com/dev/awards/alliedhealth/thankyou.html";
</script>
!!EOX!!
}