I need to accept a form submission,
capture the name of a file (name is passed in the cgi
param), extract the user's email address
from the form data, save the form data to a log file,
attach the file whose name corresponds to the name
passed in the cgi param and email it to the user.
I think I've captured and regexed the form data properly,
I've written the data to a hash, and opened the pipe to sendmail.
The questions are: are there any obvious problems in the code so far AND
how the heck do you attach a file to sendmail ??
here's the code I have now .. with comments removed for space
use strict;
use CGI;
$sendmail = '/usr/lib/sendmail';
$file = param('file');
$formdata=<STDIN>;
$formdata=~s/\s+$//;
foreach (split(/&/, $formdata))
{
($name, $value)=split(/=/, $_);
$name=~s/\+/ /g;
$name=~s/%([0-9|A-F]{2})/pack(C,hex($1))/eg;
$value=~s/\+/ /g;
$value=~s/%([0-9|A-F]{2})/pack(C,hex($1))/eg;
$formash{$name} = $value;
}
$receiver = $formash{email};
open(SENDMAIL, "|$sendmail") or die "Cannot open $sendmail: $!";
print SENDMAIL "To: $receiver \n";
print SENDMAIL "From: info\@constellar.com \n";
print SENDMAIL "Subject: Whitepapers Request \n";
close(SENDMAIL);