Chapter 3.  Running a Form-to-Email Gateway

Now that you’re able to run real, honest-to-goodness CGI scripts, let’s make something useful: a web-form-to-email gateway. This is probably one of the most common uses of CGI scripts, since it satisfies a very common need: you have an HTML form that you want visitors to your web site to fill out, and you want the contents of that form sent to you as an email message.

My goal with this chapter is to get your form-to-email gateway script up and running as quickly as possible. Along the way I explain foreach loops, if blocks, and how Perl evaluates conditional statements for “truth.” I also touch on how to open a pipe to another program and print output to that program, as well as how to use the die function to make your script stop dead in its tracks if it notices something unusual happening.

Because you still are at a fairly early stage in your Perl education, I’m going to ask you to take more or less on faith some other Perl features demonstrated in this chapter. I’ll explain what they’re doing in terms of this chapter’s example, but I will stop short (for now) of giving a complete explanation of how you would use them in other circumstances. This is the case with this chapter’s treatment of the substitution operator, and the CGI.pm module, for example. Don’t worry, though. We’ll be covering them more thoroughly in the chapters ahead.

Checking for CGI.pm

We’re going to make life easy for ourselves by writing this script using something ...

Get Perl for Web Site Management now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.