CMPS 335 Advanced Web Publishing
Perl CGI Programming
Assignment 3, Spring 2002
Emailing Form Data
Forms are used to obtain data from visitors. Most
form owners want the data returned to them. One of the common uses
of email is to email form data. For this assignment, you need to
design and create a registration form to collect data and
write a CGI script to email the data back to you.
Simple Mail Transfer Protocol (SMTP) is the specification used to
transmit email messages across the Internet. If you have an
email
account, you are using an SMTP mail server. The most popular
implementation of SMTP is the sendmail program. A CGI script
can communicate with the sendmail program by opening a pipe to it
with the open statement. The sendmail program sends messages to one
or more recipients. From a Unix platform, you can use sendmail
directly without going through an email client program such as Nestscape
mail or Eudora.
Part A -- Creating A Web-based Registration Form
Write an HTML document to generate a registration form
for obtaining visitor's information. This registration form should
contain at least the following elements:
- Input boxes
For the last name, first name, title, street address, state,
zip code, phone, and email address.
- Two radio buttons (gender)
- A pull-down menu (age groups)
- A textarea box (for comments)
- A submit button
- A reset button
(Example of a Completed Registration Form)
Part B -- Creating a CGI Script for Emailing Form Data
The address of the sendmail program on our Web server is:
/usr/sbin/sendmail. Your CGI script should open a pipe to re-direct
the output of the script to the sendmail program.. Your script also
needs to specify the recipient of the email. The recipient should be
your email address for this assignment. These things can be accomplished
by the following statements:
#!/usr/bin/perl
require "subroutines.lib";
&Parse_Form;
$recipient = 'yourEmailAddress';
$lastname = $formdata{'lastname'};
$firstname = $formdata{'firstname'};
$name = "$firstname $lastname";
:
: (get data from %formdata)
:
$agegroup = $formdata('agegroup'};
$comments = $formdata{'comments'};
open (EMAIL,"|/usr/sbin/sendmail -t") || return 0;
With the -t switch, The sendmail program scans the message for
recipient address. Your script then prints out the header
information for mail message, the data (mail message), and closes the input stream
so the message actually gets mailed.
#Print the header information for the mail
print EMAIL "To: $recipient\n";
print EMAIL "From: $name ($email)\n";
print EMAIL "Subject: Form Data\n\n";
#Print out email message
print EMAIL "$title $ lastname\n";
print EMAIL "$firstname\n";
:
:
print EMAIL "$agegrout\n";
print EMAIL "$comments\n";
close(EMAIL);
Finally, your script generates a Thank You page to acknowledge
receipt of the registration data. On this Thank You page, your
script should also display the registration data.
print <<"EOF";
<html>
:
:
<font size=+3 color=blue>Thank you for registering</font><br>
<ul>
<li>$title $firstname $lastname
<li>$geneder $agegroup
:
:
<li>$comments
</ul>
</body>
</html>
EOF
(Example of a Thank You web page)
Thank you for your registration
- Mr. David Anderson
- male 20to35
- 985-4268241 danderson@selu.edu
- I am a computer science student at Southeastern Louisiana University
Click Here for an
example of registration form
Return to Home Page