First time here? First time here? Newsletter Signup Newsletter
651326 Members and growing! | Flash Jobs
Search tutorials
Author: Thomas Watson | Website: http://hikercentral.net
#!/usr/local/bin/perl

# NOTE- on above line- your path to PERL could be different!
# If you're not sure, check with your web host.

###########################################################
# accepts data post from 'contact us' page and emails data
# written 04/28/02 by thomas watson http://hikercentral.net
###########################################################

# NOTE- again, your path to sendmail could be different
$mailprog = "/usr/lib/sendmail";

# NOTE- this is where you want the email sent to.
# Be sure and "escape" the "@" sign. 
$recipient = "wendy\@mymail.com";


# get the input
# put it in $buffer
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

# split the input into name-value pairs
@pairs = split(/&/, $buffer);

# standard processing loop
# this will un-URLencode as many variables as you send and place
# in an array ($FORM).
foreach $pair (@pairs) {
   # split the name-value pair into name and value
   ($name, $value) = split(/=/, $pair);
   # convert '+' to space
   $value =~ tr/\+/ /;
   # convert embedded comma to space delimiting purposes
   $value =~ tr/\,/ /;
   # convert hex symbols to alphanumeric
   $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("c", hex($1))/ge;
   $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("c", hex($1))/ge;   
   $value =~ s/<%lt%>!--(.|\n)*--<%gt%>//g; 
   # create new array with each name and value as elements
   $FORM{$name} = $value;
}

# now assign a variable name to each value from the input array
$NAME = $FORM{'name'};
$EMAIL = $FORM{'email'};
$SUBJECT = "Web Site Inquiry";
$COMPANY = $FORM{'company'};
$PHONE = $FORM{'phone'};
$MESSAGE = $FORM{'message'};

# next we have to re-URLencode any values being sent back to flash.
# for my contact form I'm only going to send the name.
$NAME =~ tr/ /\+ /;


# this assigns a "name" to our name/value pair being sent
# and sends it back to flash through the standard output stream.
# be sure and note the content type!
print "Content-type: application/x-www-urlform-encoded\n\n";
print  "rtn_name=$NAME";

# now we open a stream to "sendmail" and send the email
# using the variables from above.
open (MAIL, "|$mailprog $recipient") || die "Can't open $mailprog!\n";
print MAIL "To: $recipient\n";
print MAIL "From:$EMAIL\n";
print MAIL "Subject: $SUBJECT\n";  
print MAIL "------------------------------------------------------\n";
print MAIL "$MESSAGE\n\n";
print MAIL "$NAME\n";
print MAIL "$COMPANY\n";
print MAIL "$PHONE";

close (MAIL);

exit;
» Level Intermediate

Added: 2002-05-07
Rating: 9 Votes: 81
(10 being the highest)
» Author
Tom Watson is a Flash developer currently residing in Nashville, Tennessee. He's been an independant contractor in the computer business since 1989, working on web projects since the web was introduced to the Internet in 1994.
» Download
Download the files used in this tutorial.
» Forums
More help? Search our boards for quick answers!

Comments

  • There are no comments yet. Be the first to comment!

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.
Featured Flash FLA
» Author: work2survive
» Title: Girl Walking 1kb
» Description: Walking girl, animation just takes 1kb, using high heels shoes, and fashion model attitude.
Featured Sound Loops
Image for equalize

Audio Player

» Author: BoxCat
» Title: CPU Talk
» Description: From the cyberpunk RPG, "Nameless: the Hackers" Completely Free to use! Keywords: edm hip hop rap electronic mysterious mission hacking chase exciting spy ios ambient chilling love happy sad angry suspense
Latest Font
» Author: Fábio FAFERS
» Description: I created this font for free use. Everyone can apply it in personal or business texts. Its free, but I want to be communicated in case of business use. Donations are accepted to keep the project of free fonts alive! Thank you all
Featured Sound Fx
Image for equalize

Audio Player

» Author: nathan
» Description:

A recorded sound of the Dimensional Fork Gate.