Check out merlyn's article on the subject; I found it very useful when working on a similar project.
While working on the project, I made some observations you may find helpful (note that the following code has been simplified from the final, so certain typos may have been made):
You can add additional portions to the email header by calling the add method of your MIME::Lite object. For example, my project allowed optional copies sent to other recipients:
if ( $copiesto ) { $msg->add( CC => $copiesto ); }
If you want the uploaded file as a separate attachment (as opposed to inline with the message body), control that with Disposition. For example:
$msg->attach ( Disposition => 'attachment', Type => $sentinfo->{ 'Content-Type' }, Encoding => 'base64', Filename => $sentname, FH => $sentfile );
Also note that the above sets the attachment type according the the information provided by the browser, though be aware that you may get weird results when certain MIME types use the same extensions. For example, I uploaded a stylesheet during testing and it was described as a Comet Systems Cursor in the email message. Your mileage may vary.
During development, I enabled a Debug flag to help me troubleshoot problems. This resulted in a second attachment containing information I thought relevant at the time. For example:
if ( defined( $settings{ "DEBUG" } ) ) { $msg->attach ( Type => 'TEXT', Encoding => 'base64', Filename => 'debug.txt', Disposition => 'attachment', Data => [ "Upload info\n\n", "File size = $sentsize\n", ( map { "$_ = $sentinfo->{ $_ }\n" } sort keys %$se +ntinfo ), "\n", "ENV Contents:\n\n", ( map { "$_ = $ENV{ $_ }\n" } sort keys %ENV ), "\n", "Configuration Settings:\n\n", ( map { "$_ = $settings{ $_ }\n" } sort keys %setti +ngs ) ] ); }
You may find it helpful to use File::Basename to set the file name of the attachment, especially if you're getting uploads from Win32 clients and people are uploading files using long file names. My quick and dirty hack for this was something along these lines:
my $cgi = new CGI; my $sentfile = $cgi->upload( 'sentfile' ); my $sentsize; my $sentinfo; my $sentname; if ( $sentfile ) { $sentsize = -s ( $sentfile ); # file size $sentinfo = $cgi->uploadInfo( $sentfile ) ; fileparse_set_fstype( "MSDOS" ); # risky assumption? my ( $sentname ) = fileparse( $sentfile ); }
It's not perfect by any means, but it worked well and was a reasonably easy job--once I had merlyn's starting point.
In short, merlyn's article is very helpful, but you'll want to read the MIME::Lite docs pretty carefully and to experiment with the article's code to see how it works on your system.
Also, there are several other threads in the archives that offer alternative approaches and other information.
--f
In reply to Re: submit form data thru email
by footpad
in thread submit form data thru email
by quietone
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |