Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: web form email attachment

by csuhockey3 (Curate)
on Oct 23, 2004 at 07:30 UTC ( #401780=note: print w/replies, xml ) Need Help??

in reply to web form email attachment

For a file upload form, MIME::Lite is the way to go, but I found a really old one I did a while back that uses MIME::QuotedPrint and MIME::Base64 if you are interested -- it's old, but should give you a good place to start and some ideas. Sort of the full calorie MIME::Lite. I echo joost about the danger of spammer abuse with a script like this -- is this form going to be wide open to the net?

#!/usr/bin/perl -w use MIME::Base64; use MIME::QuotedPrint; use Mail::Sendmail; use CGI qw(:standard); use CGI::Carp qw/ fatalsToBrowser /; # remove for production my $cgi = new CGI; print $cgi->header; print $cgi->start_html(); #get values as below my $a_File = $cgi->param('image'); ... if($a_File =~ m!/!){ @data = split /\//, $a_File; $a_Filename = pop @data; }elsif($a_File =~ m!\\!){ @data = split /\\/, $a_File; $a_Filename = pop @data; }else{ $a_Filename = $a_File; } if ($a_Filename){ open(a_tmpFile, "</tmp/$a_Filename") or die $!; binmode a_tmpFile; undef $/; while(<a_tmpFile>){ $base64_a_File = $base64_a_File . encode_base64($_); } close a_tmpFile; } ########### MESSAGE ##################### %mail = ( SMTP => '', from => '', to => '', subject => '', ); $boundary = "====" . time() . "===="; $mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\""; $boundary = '--'.$boundary; $mail{body} = <<END_OF_BODY; $boundary Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable if($a_Filename){ $mail{body} = $mail{body} . <<END_OF_A_FILE; $boundary } #would list all params here #param: $value as examples below Contact Name: $contactName Contact Phone: $contactPhone Contact Email: $contactEmail if($a_Filename){ $mail{body} = $mail{body} . <<END_OF_A_FILE; $boundary Content-Type: application/octet-stream; name="$a_Filename" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="$a_Filename" $base64_a_File END_OF_A_FILE } END_OF_BODY sendmail(%mail) || print "Error: $Mail::Sendmail::error\n"; print "<p><b>Thank You.</b>"; #END
note: This is an old script and I stripped out the extraneous code and left what is important, thus it is untested.

Replies are listed 'Best First'.
Re^2: web form email attachment
by koryw (Novice) on Nov 30, 2004 at 23:37 UTC
    I tried running the code above, modifying it to suit my needs and I'm receiving a "SOFTWARE ERROR:" which is produced from the CGI::Carp qw/ fatalsToBrowserr module on line 30 of the code. Here is that line open(a_tmpFile, "</tmp/$a_Filename") or die $!;
      post that snippet so we can have a look at it...Like I said, I stripped it pretty good to get to the meat of the deal, but I am happy to be more help if you post some of the code.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://401780]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (2)
As of 2021-09-28 19:55 GMT
Find Nodes?
    Voting Booth?

    No recent polls found