Web Teacher Software
web database
Javacript 
Tutorial
CGI tutorial
web 
database consulting
web database training
contact us about web 
database software
press
Hosted Database Solutions
webteacher home
Web Teacher Consulting
CGI - A free tutorial for the Total Non-Programmer.
CGI - Let's get startedCGI - Introduction to Perl

The e-mail subroutine


#*****************BEGIN BODY*************

print "<h1>Thank you for filling out the form</h1>";

$firstname = $value[0];
$lastname = $value[1];
$email = $value[2];
 
print "Your first name is $firstname<BR>";
print "Your last name is $lastname<BR>";
print "Your e-mail is $email<BR>";

$to = $email;
$from = "clinton\@whouse.gov";
$sub = "subject of my first e-mail";
$body = "The form was filled out by $firstname $lastname
Thank you goes on another line.";

&email($to,$from,$sub,$body);
 
#***************END BODY******************



In the example above I have added 7 lines (including the blank one) to the end of the program body.  You will want to copy these lines, and append them to the body of test2.cgi.  There are 2 ways to do this.


 
  • You can copy the lines into your PC editor, and then upload the file again with an FTP program

  •    You will not need to run chmod again.
  • You can run Emacs or Pico from the Unix prompt, make the changes, then save and exit.

Once you have appended the additional lines to the body of test2.cgi you can try the form again.  Be sure to enter your own email address on the testform.htm page, or else someone will get a very confusing message.  When you submit the form, it will show you the same display as before.  This time, however, if you check your e-mail after a few seconds, you will have a message from President Clinton.


 

Let's review the additional lines:


 
$to = $email;
          

This line simply copies the contents of the variable $email to the variable, $to.

$from = "clinton\@whouse.gov";

    This line set the variable $from equal to clinton@whouse.gov.  The backslash (\) is called an escape characterThe @ sign has a special meaning in Perl, the @ sign refers to an array .  In this case, we don't want to refer to an array, we just want to type an @ sign.  Freud once said that "sometimes a cigar is only a cigar."  The backslash tells Perl that in this particular case, the @ sign is only an @ sign.
    For example, if I typed the line
            $amount = "He owes me $20.00";
    I would get an error, because Perl would try to access an variable called $20.00.  If I escaped the $ sign, like this:
            $amount = "He owes me \$20.00";
    Then the line would work fine.
$sub = "subject of my first e-mail";
        

This one is pretty straightforward.

$body = "The form was filled out by $firstname $lastname
Thank you goes on another line.";

    This is only 1 command.  Remember, Perl commands always end with a semicolon (;).  The return character is simply another character in the text string assigned to $body.  This is very convenient, because it allows you to type the open quotes, then type your multi-line text just as you would in a word processor, and then close the quotes.  Finally, you will type a semicolon when you are through with that command.
    I could also have typed this and gotten the same result:
       $body = "The form was filled out by $firstname $lastname \n Thank you goes on another line.";

    The \n character is a newline.  When the double quotes contain an \n , they interpret it into a carriage return in Ascii (plain text).  This works for e-mail, which is written in Ascii, but not for HTML.  Remember that HTML does not care whether the source code is on one line or many.  If you want to drop to a new line in HTML, you have to insert a <BR> or <P> tag.

&email($to,$from,$sub,$body);
     The email subroutine is defined down below the readparse subroutine.  It has been configured to be very easy to use.  Simply type
          &email( addressee , reply-to, subject, message body)
    You could have bypassed the previous 4 commands and simply typed this:
        &email($email,"clinton\@whouse.gov","subject of my first e-mail","This is line 1 \nThis is line 2");
    However, I think it easier to edit and read if you assign the values seperatly, as we did in our program.


BACKHTML Form | Guestbook Form | Hit Counters

Home | WebData - Web Database Software | Javascript | CGI | Consulting | Map Builder | Contact Us | The Press Room