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);
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.