Search tutorials
#!/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 |
» 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. |
Download (569 kb) |
» Forums |
More help? Search our boards for quick answers! |
-
You must have javascript enabled in order to post comments.
Comments
There are no comments yet. Be the first to comment!