Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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.

In reply to Re: web form email attachment by csuhockey3
in thread web form email attachment by koryw

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • 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, 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, 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others cooling their heels in the Monastery: (7)
    As of 2021-03-05 22:51 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      My favorite kind of desktop background is:











      Results (115 votes). Check out past polls.

      Notices?