1. Home
  2. Computing & Technology
  3. Web Design / HTML

Using Forms and CGI

By Jennifer Kyrnin, About.com

6 of 6

Second Half of the CGI

This is the section of the script that sends the email. You need to know where sendmail is located on your server in order to use it. Also, always make sure that you include a Reply-to line in your email message. Since this mail is sent by the Web server, it could mess up the headers if you don't include that line.

sub sendemail
{
 open (SENDMAIL, "| /usr/bin/sendmail -t -n");
 print SENDMAIL <<EOM

From: from\@abc.com
To: to\@abc.com
Reply-to: from\@abc.com
Subject: Email from the mail form

This is a message from your mail form. The form results are:

fullname = $in{'full_name'}

EOM

}

This prints a thank you page that thanks the reader for submitting the form. You can include any HTML elements that you would put on a normal HTML page, including JavaScript and other dynamic elements.

sub printthanks
{

 print "Content-type: text/html \n\n";
 print <<"EOM";

<html>
<head>
<title>Thanks for Submitting the Form</title>
</head>
<body bgcolor="#ffffff">
<h2>Thank you for answering our form</h2>
You should receive a response shortly.
</body>
</html>
EOM

 print "";

}

Previous Features

Explore Web Design / HTML
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Web Design / HTML
  4. About.com Web Design A to Z
  5. Web Design Articles R-Z
  6. Web Design/HTML Articles U
  7. Using Forms and CGI

©2009 About.com, a part of The New York Times Company.

All rights reserved.