CGI and Perl

E-Mail Notification

The next and last example shows you how you can set up a Web page to automatically send
e-mail. What this example does is keep a database of license plate numbers and their owners'
e-mail addresses. If a person sees a car with the lights left on, he or she can bring up this Web page and send an automatic e-mail notification to the owner of that car.


The first thing you need is a database of license plate numbers. You can use the same format as in the guest book example. The only difference would be the fields that are stored in the database. In addition to the license plate number, you should store the owner's name and e-mail address, as well as the color, make, and model of the car. The database will have the following format:


Displaying the Form

The next thing you need is the form that allows users to issue the e-mail notification. This form is another simple one. You'll use a field to indicate the license plate number, another field for the user to enter his or her name, and two submission options. The first submit option is to send
e-mail to the owner. The other submit option is to display only the license plate information. The form code looks like Listing 7.11.

Listing 7.11. Subroutine to print a license plate form.

sub licensePlateForm {
    print "<P>Please enter a license plate number";
    print " and select one of the options.\n";
    print "<P><B>Notify</B> will send e-mail to the owner.\n";
    print "<P><B>Query</B> will display the information about";
    print " this license plate.\n";
    print $q->start_multipart_form();
    print "<P>License plate: ";
    print $q->textfield(-name=>`LicensePlate',-maxlength=>7,-size=>7);
    print "<P>Your name: ";
    print $q->textfield(-name=>`FindersName',-maxlength=>32,-size=>32);
    print "<BR><BR><BR>";
    print $q->submit(-name=>`Action',-value=>`Query');
    print " ";
    print $q->submit(-name=>`Action',-value=>`Notify');
    print " ";
    print $q->reset();
    print $q->endform();

This form is shown in Figure 7.6.

The license plate search form
Figure 7.6. The license plate search form.