in reply to web form email attachment
note: This is an old script and I stripped out the extraneous code and left what is important, thus it is untested.#!/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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: web form email attachment
by koryw (Novice) on Nov 30, 2004 at 23:37 UTC | |
by csuhockey3 (Curate) on Dec 03, 2004 at 21:49 UTC |