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

comment on

( [id://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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-25 15:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found