O'Reilly logo

Sams Teach Yourself CGI in 24 Hours, Second Edition by Rafe Colburn

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Example: Sending Email from a CGI Script

Let’s look at a simple example that illustrates how email is sent using a CGI script. I’ve written a CGI script (email-form.pl) that presents users with a form that requests their email address, a subject, and a message body. When the user fills out the form fields and submits the form, an email message with the subject and body that they entered is sent to the email address specified in the script. Theoretically, the email address is their own, but that’s not necessary. The full source code for the script appears in Listing 8.2.

Listing 8.2. The Source Code for email-form.pl
 1: #!/usr/local/bin/perl 2: 3: use CGI; 4: use Net::SMTP; 5: 6: my $query = new CGI; 7: my $smtp = Net::SMTP->new('localhost'); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required