If you're just looking for a way to get the input from the form, I'd have to suggest using the CGI.pm module. The use of modules is stressed here for good reason and I believe the CGI.pm module is fairly standard. Then you could just do something like
use CGI;
$fav_color = param("favorite_color");
to get the variable input. I'd consult OVID's tutorial mentioned above for the exact usage of the CGI module.
If you
really don't want to use any modules, the following code will create a hash called formdata which contains the form input as name/value pairs.
sub parse_form {
my (@pairs, $buffer, $value, $key, $pair);
if ($ENV{'REQUEST_METHOD'} eq 'GET') {
@pairs = split(/&/, $ENV{'QUERY_STRING'});
}
elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {
read (STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
}
else {
print "Content-type: text/html\n\n";
print "<P>Use Post or Get";
}
foreach $pair (@pairs) {
($key, $value) = split (/=/, $pair);
$key =~ tr/+/ /;
$key =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~s/<!--(.|\n)*-->//g;
if ($formdata{$key}) {
$formdata{$key} .= ", $value";
}
else {
$formdata{$key} = $value;
}
}
return %formdata;
}
You'd then call the subroutine with something like
my %formdata = &parse_form
After you get the form information, using either of the above mentioned methods, you can use the sendmail program, which is standard on most any *NIX box.
open (MAIL, "|/usr/bin/sendmail -t") or die "Error";
print MAIL "To: to@address.com \nFrom: from@address.com\n";
print MAIL "Subject: mail subject\n";
print MAIL "Add the contents here\n";
close (MAIL);
Hope this helps. -Eric
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.