Writing the E-mail Texas

The fourth primer in the PERL Series builds on first three.

Local Companies

SoloComputers.com
915-204-8163
7903 Pinebrook Dr.
San Antonio, TX
Information Processing Corporation
972-404-9244
13747 Montfort, Suite 300
Dallas, TX
HRsmart
972-740-9421
2929 N.Central Expressway
Richardson, TX
Catalis, Inc.
(512) 874-7664
7801 N. Capital of Texas Hwy
Austin, TX
Parts-People.Com Inc
512-339-1990
3106 Industrial Terrace
Austin, TX
Heatwave Interactive
512-553-0607
P.O. Box 369
Cedar Park, TX
Maxtrus Micro
(800) 910-2380
4781 Snow Dr
Mesquite, TX
MLM Software
+1-402-524-6464
Berkeley House
Bristol, TX
Palindrome Software Labs Ltd
206-366-5542
7700 WillowChase BLVD
Houston, TX
Delta Business Solutions
(281) 445-3600
525 N. Sam Houston PKWY E
Houston, TX

provided by: 
Originally published at Internet.com


Now we get into the fun part. Plus, now we're far enough along that you can start to alter the script yourself. In fact, I'll give you your first chance to alter the script in your first assignment at the end of the Primer.

Did you know there would be a test?

-----------------------------------

Our Variables

At this point, we have four pieces of information set to scalar variables. They are:

* $FORM{'name'} This is the value written into the first text box.

* $FORM{'email'} This is the value written into the second text box.

* $FORM{'submitaddress'} This is the email address where the form should be sent. It's the hidden input element. You didn't forget about this one, did you?

* $FORM{'feedback'} This is the text that was written into the textarea box.

The Email Module

Now, believe it or not, this stuff starts to become fun. Let's write an email letter. Here's the module of code that writes the letter taken from the Guestbook script: Here's the code open (MESSAGE,"| /usr/lib/sendmail -t"); print MESSAGE "To: $FORM{submitaddress}\n"; print MESSAGE "From: $FORM{name}\n"; print MESSAGE "Reply-To: $FORM{email}\n"; print MESSAGE "Subject: Feedback from $FORM{name} at $ENV{'REMOTE_HOST'}\n\n"; print MESSAGE "The user wrote:\n\n"; print MESSAGE "$FORM{feedback}\n"; close (MESSAGE); &thank_you;

We begin by using the command "open" to open a process. "Open" will also you to open a file, read, or append to a file, but we need to open a process right now.

Look at the format, inside the parentheses are two pieces of information separated by a pipe (|). The first text "MESSAGE" will act as the "filehandle" that will represent the file we're about to write. I chose to call the file MESSAGE. You can change it to whatever you want as long as you make it a unique identifier word representing on the file you're going to create.

The text "| /usr/lib/sendmail -t" explains what we're going to do with this file named MESSAGE. We're going to send it to the server's mail program called "sendmail".

What I have written here is the most common path to a server mail program. Your server may be different. If so, change that here. We'll be sending it as text.

Commands & Operators

In building the email message, we'll need to follow some rules and learn some new commands and an operator:

* print: This does just what it says. It prints to the page. Note the format. The text is included in double quotes and each line ends with a semi-colon.

* close: This will close MESSAGE when we're done writing it: * \n: This backslash "n" means "new line" If you want double spacing, use two: \n\n.

There's nothing to it now; let's build it.

---------------------------------

Let's Build It

I wrote this part of the code simply by opening my Eudora email program and listing the elements it asks for, in the order it asks for them. I followed the format of spelling and capitalization.

Remember thhat in the print command, the scalar variables get stuck in there as if they were the text you want because once this script runs, they will be. Here's the email header: print MESSAGE "To: $FORM{submitaddress}\n"; print MESSAGE "From: $FORM{name}\n"; print MESSAGE "Reply-To: $FORM{email}\n";

We print to the MESSAGE "To: $FORM{submitaddress}" and then skip a line. Note again, the line ends with a semi-colon. There's no way around this rule. Every line ends with a semi-colon.

You can see what happens: the "submitaddress" value, which is your email address, gets stuck in there when the script rolls.

The next line is the name the person entered and the next is the reply address the person entered into the text box that asked for his or her email box.

This isn't so hard. Let's build the body of the email:

print MESSAGE "Subject: Feedback from $FORM{name} at $ENV{'REMOTE_HOST'}\n\n"; print MESSAGE "The user wrote:\n\n"; print MESSAGE "$FORM{feedback}\n";

The first line creates the subject telling you that you have feedback from whatever the person entered into the NAME textbox.

Next I used a little PERL shorthand to grab the name of the server sending the mail. Remember that $ENV represents all the data from the form? We used it last time to pluck out the request method. Well, here I'm using it again to pull out the remote host. It's a quick way of adding where the letter came from.

We end with two lines.

The final two lines simply write a quick intro, "The user wrote", skips two lines and then writes the value that was found within the textarea box.

Got it? Let's wrap it up. close (MESSAGE); &thank_you; We close MESSAGE because we're done with it. Then something new. See that: &thank_you That's what's known as "calling for a subroutine". If, in the script, you look just below the code we are working on here, you'll see the line: sub thank_you All of the text that follows that line will be used to write the thank you page. In PERL lingo, that code is called a subroutine. It's a lot like a function in JavaScript. The final line of the module that writes the email letter calls on that subroutine. It acts as a trigger.

This keeps everything in order. First we grab and delineate the form data, then we write and send the email, lastly we trigger the subroutine that writes the thank-you page.

It's very clean, very simple, and a little easier to understand than the last primer.

We'll get into that thank_you subroutine and talk a little about how to require modules in PERL in Primer Five.

Now, put your books away. It's time for your assignment.

Primer Four Assignment

Can you alter the email code above so that the person that submitted the form gets a copy of the email?

If that's a little much for you, can you add another line at the bottom of the email that reads, "Thanks for writing" and then prints the submitter's name?

Can you do both? Think it through and look at an email program for the syntax for the carbon copy.

(This will open in a new window.) :
Here's a possible answer.

Author: Joe Burns

Read article at Internet.com site

Featured Local Company

Heatwave Interactive

512-553-0607
P.O. Box 369
Cedar Park, TX
http://www.heatwaveinteractive.com

Located in Austin, Texas, Heatwave Interactive is an entertainment software company whose mission is to create original, character-based games that unite the power of online gaming with the excitement of traditional video games.

Regional Articles
- Writing the E-mail Abilene TX
- Writing the E-mail Alamo TX
- Writing the E-mail Alice TX
- Writing the E-mail Allen TX
- Writing the E-mail Alvin TX
- Writing the E-mail Amarillo TX
- Writing the E-mail Angleton TX
- Writing the E-mail Arlington TX
- Writing the E-mail Austin TX
- Writing the E-mail Azle TX
- Writing the E-mail Baytown TX
- Writing the E-mail Beaumont TX
- Writing the E-mail Bedford TX
- Writing the E-mail Beeville TX
- Writing the E-mail Bellaire TX
- Writing the E-mail Belton TX
- Writing the E-mail Big Spring TX
- Writing the E-mail Boerne TX
- Writing the E-mail Borger TX
- Writing the E-mail Brenham TX
- Writing the E-mail Brownsville TX
- Writing the E-mail Brownwood TX
- Writing the E-mail Bryan TX
- Writing the E-mail Burleson TX
- Writing the E-mail Canyon TX
- Writing the E-mail Carrollton TX
- Writing the E-mail Cedar Hill TX
- Writing the E-mail Cedar Park TX
- Writing the E-mail Channelview TX
- Writing the E-mail Cleburne TX
- Writing the E-mail Cleveland TX
- Writing the E-mail Clute TX
- Writing the E-mail College Station TX
- Writing the E-mail Colleyville TX
- Writing the E-mail Conroe TX
- Writing the E-mail Converse TX
- Writing the E-mail Coppell TX
- Writing the E-mail Copperas Cove TX
- Writing the E-mail Corpus Christi TX
- Writing the E-mail Corsicana TX
- Writing the E-mail Crosby TX
- Writing the E-mail Cypress TX
- Writing the E-mail Dallas TX
- Writing the E-mail Dayton TX
- Writing the E-mail Deer Park TX
- Writing the E-mail Del Rio TX
- Writing the E-mail Del Valle TX
- Writing the E-mail Denison TX
- Writing the E-mail Denton TX
- Writing the E-mail Desoto TX
- Writing the E-mail Dickinson TX
- Writing the E-mail Donna TX
- Writing the E-mail Dumas TX
- Writing the E-mail Duncanville TX
- Writing the E-mail Eagle Pass TX
- Writing the E-mail Edinburg TX
- Writing the E-mail El Campo TX
- Writing the E-mail El Paso TX
- Writing the E-mail Ennis TX
- Writing the E-mail Euless TX
- Writing the E-mail Floresville TX
- Writing the E-mail Flower Mound TX
- Writing the E-mail Fort Worth TX
- Writing the E-mail Friendswood TX
- Writing the E-mail Frisco TX
- Writing the E-mail Galveston TX
- Writing the E-mail Garland TX
- Writing the E-mail Gatesville TX
- Writing the E-mail Georgetown TX
- Writing the E-mail Gilmer TX
- Writing the E-mail Granbury TX
- Writing the E-mail Grand Prairie TX
- Writing the E-mail Grapevine TX
- Writing the E-mail Greenville TX
- Writing the E-mail Groves TX
- Writing the E-mail Haltom City TX
- Writing the E-mail Harker Heights TX
- Writing the E-mail Harlingen TX
- Writing the E-mail Henderson TX
- Writing the E-mail Houston TX
- Writing the E-mail Humble TX
- Writing the E-mail Huntsville TX
- Writing the E-mail Hurst TX
- Writing the E-mail Irving TX
- Writing the E-mail Jacksonville TX
- Writing the E-mail Joshua TX
- Writing the E-mail Katy TX
- Writing the E-mail Kaufman TX
- Writing the E-mail Keller TX
- Writing the E-mail Kerrville TX
- Writing the E-mail Kilgore TX
- Writing the E-mail Killeen TX
- Writing the E-mail Kingsville TX
- Writing the E-mail Kyle TX
- Writing the E-mail La Porte TX
- Writing the E-mail Lake Jackson TX
- Writing the E-mail Lancaster TX
- Writing the E-mail Laredo TX
- Writing the E-mail League City TX
- Writing the E-mail Leander TX
- Writing the E-mail Levelland TX
- Writing the E-mail Lewisville TX
- Writing the E-mail Livingston TX
- Writing the E-mail Lockhart TX
- Writing the E-mail Longview TX
- Writing the E-mail Lubbock TX
- Writing the E-mail Lufkin TX
- Writing the E-mail Mabank TX
- Writing the E-mail Magnolia TX
- Writing the E-mail Mansfield TX
- Writing the E-mail Marble Falls TX
- Writing the E-mail Marshall TX
- Writing the E-mail Mc Kinney TX
- Writing the E-mail Mcallen TX
- Writing the E-mail Mercedes TX
- Writing the E-mail Mesquite TX
- Writing the E-mail Midland TX
- Writing the E-mail Mineral Wells TX
- Writing the E-mail Mission TX
- Writing the E-mail Missouri City TX
- Writing the E-mail Nacogdoches TX
- Writing the E-mail Navasota TX
- Writing the E-mail Nederland TX
- Writing the E-mail New Braunfels TX
- Writing the E-mail New Caney TX
- Writing the E-mail North Richland Hills TX
- Writing the E-mail Odessa TX
- Writing the E-mail Orange TX
- Writing the E-mail Palestine TX
- Writing the E-mail Pampa TX
- Writing the E-mail Paris TX
- Writing the E-mail Pasadena TX
- Writing the E-mail Pearland TX
- Writing the E-mail Pflugerville TX
- Writing the E-mail Pharr TX
- Writing the E-mail Plainview TX
- Writing the E-mail Plano TX
- Writing the E-mail Port Arthur TX
- Writing the E-mail Port Lavaca TX
- Writing the E-mail Porter TX
- Writing the E-mail Red Oak TX
- Writing the E-mail Richardson TX
- Writing the E-mail Richmond TX
- Writing the E-mail Rio Grande City TX
- Writing the E-mail Robstown TX
- Writing the E-mail Rockport TX
- Writing the E-mail Rockwall TX
- Writing the E-mail Roma TX
- Writing the E-mail Rosenberg TX
- Writing the E-mail Rosharon TX
- Writing the E-mail Round Rock TX
- Writing the E-mail Rowlett TX
- Writing the E-mail San Angelo TX
- Writing the E-mail San Antonio TX
- Writing the E-mail San Benito TX
- Writing the E-mail San Marcos TX
- Writing the E-mail Schertz TX
- Writing the E-mail Seabrook TX
- Writing the E-mail Seagoville TX
- Writing the E-mail Seguin TX
- Writing the E-mail Sherman TX
- Writing the E-mail Silsbee TX
- Writing the E-mail South Houston TX
- Writing the E-mail Southlake TX
- Writing the E-mail Spring TX
- Writing the E-mail Springtown TX
- Writing the E-mail Stephenville TX
- Writing the E-mail Sugar Land TX
- Writing the E-mail Sulphur Springs TX
- Writing the E-mail Temple TX
- Writing the E-mail Terrell TX
- Writing the E-mail Texarkana TX
- Writing the E-mail Texas City TX
- Writing the E-mail The Colony TX
- Writing the E-mail Tomball TX
- Writing the E-mail Tyler TX
- Writing the E-mail Universal City TX
- Writing the E-mail Uvalde TX
- Writing the E-mail Victoria TX
- Writing the E-mail Vidor TX
- Writing the E-mail Waco TX
- Writing the E-mail Waxahachie TX
- Writing the E-mail Weatherford TX
- Writing the E-mail Weslaco TX
- Writing the E-mail Wharton TX
- Writing the E-mail Wichita Falls TX
- Writing the E-mail Willis TX
- Writing the E-mail Woodway TX
- Writing the E-mail Wylie TX
Related Articles
- Security Issues in Perl Scripts Texas
Perl is one of the most widely used languages for writing interactive applications on the Web, and Perl programs are widely used for various system administration tasks. Applications that serve these tasks must provide reliable access to security sensitive functions and information, and at the same time ensure that no one is granted access to data or functionality that was not intended for them. In this two-part article, Jordan Dimov and John Viega evaluate some of the common security weaknesses and vulnerabilities of Perl applications and give an overview of the features that the Perl language provides to aid the programmer in hardening the security of their applications.
- Programming Microsoft .NET : Web Forms Texas
- So, You Want a Discussion Group, Huh? Texas
- Implementing Interfaces in VB .NET Texas
- Diary of a Web Developer: Fork in the Road Texas
- So, You Want to Print with JavaScript, Huh? Texas
- Power Point Transistions Texas
- Replace the Space With a (+) Texas
- So, You Want A Menu, Huh? Texas
- Programming with C# - - 101 Texas
Related Local Events
PBIOS - Permian Basin International Oil Show 2010
Dates: 10/19/2010 - 10/21/2010
Location: Ector County Coliseum Complex
Midland, TX
View Details

Subsea Tieback Exhibition (SSTB)
Dates: 3/2/2010 - 3/4/2010
Location: Moody Gardens Hotel & Convention Center
Galveston, TX
View Details

Renewable Energy World Conference & Expo North America
Dates: 2/23/2010 - 2/25/2010
Location: Austin Convention Center, Austin
Austin, TX
View Details

Deep Offshore Technology (DOT 2010)
Dates: 2/2/2010 - 2/4/2010
Location: George R. Brown Convention Center
Houston, TX
View Details

Computer Measurement Group (CMG)
Dates: 12/6/2009 - 12/11/2009
Location: Gaylord Texan
Dallas, TX
View Details

Topics: 
Architecture & Design Languages & Tools Project Management Web Services
Database Microsoft & .NET Security Wireless
Java Open Source Techniques XML