#!/usr/local/bin/perl # ul_email.cgi by David Efflandt - efflandt@xnet.com # # Simple form and processing to e-mail an uploaded file attachment # Recipient of posted form (and mail errors). # Used for To and From (poster used for Reply-To): $recipient = 'you@your.domain.com'; # Possible paths to sendmail. Add your path if different. # A mail program other than sendmail might require mail routine mods: @sendmail = ( '/usr/lib/sendmail', '/usr/sbin/sendmail', '/usr/bin/sendmail', '/bin/sendmail', ); # Example of shuffling @INC to search site_perl first: # no lib '/usr/local/lib/perl5/site_perl'; # use lib '/usr/local/lib/perl5/site_perl'; # Example to find '/path/to/myperl/MIME/Lite.pm' # Edit and uncomment to add your module search path: # use lib '/path/to/myperl'; # Required perl modules use CGI qw/:standard :netscape/; # version 2.42 use MIME::Lite; print header,start_html('Upload/E-mail Test'); foreach $key (@sendmail) { if (-x $key) { $sendmail = 1; MIME::Lite->send('sendmail',"$key -t -oem"); last; } } unless ($sendmail) { $_ = join(', ',@sendmail); print h1("Can't execute sendmail"),hr,p, "Sorry, webserver can't e-mail form results from this site ", "at this time\n",p,'Searched: ',$_,p,'Please advise ', a({href=>"mailto:$recipient"},$recipient), " of this error and include site URL.\n",p,end_html; exit; } if (param('post_data')) { @back_button = (startform,hidden('Name'),hidden('E-mail'), submit({value=>' Return to Form '}),endform); unless (param('Name') && param('E-mail')) { print h1('Missing Information'),hr,p, "Your Name or E-mail address are missing from submitted form.", p,"Please go back and fill in the missing information.", @back_button,end_html; exit; } my($file,$type); my $text = "Form Info from ".virtual_host().script_name().":\n\n". "Name: ".param('Name')."\nE-mail: ".param('E-mail')."\n". "[ Other form data to be inserted here ]\n"; $text .= "\nAttached file: ".param('uploaded_file')."\n" if param('uploaded_file'); $text .= "\n-- \nBrowser: ".user_agent()."\n". "RemHost: ".remote_host()."\n\n"; $msg = new MIME::Lite From =>$recipient, 'Reply-To' =>param('E-mail'), To =>$recipient, Subject =>'Upload/E-mail Test', Type =>'TEXT', Data =>$text; if (param('uploaded_file')) { $file = param('uploaded_file'); $type = uploadInfo($file)->{'Content-Type'}; attach $msg Type =>$type, Encoding =>'base64', FH =>$file, Filename =>$file; } if ($msg->send) { print h1('Data Successfully E-mailed'),hr,p; } else { print h1('Error attemping to e-mail. '),hr,p, 'Please send e-mail to ',a({href=>"mailto:$recipient"}, $recipient),'and advise them of this problem.',p; } print 'Name: ',param('Name'),p, 'E-mail: ',param('E-mail'),p; print 'Filename: ',$file,p,'File type: ',$type,p if $file; print @back_button,end_html; exit; } print h1('Upload/E-mail Test'),hr, start_multipart_form({action=>'/~efflandt/formtest.cgi'}),p b('Required:'),p,"What's your name? ",textfield('Name'),p, "Your e-mail address? ".textfield('E-mail'),p,b('Optional:'),p, "Local file to attach? ",filefield('uploaded_file'),br, font({size=>'-1'}, 'Note: File upload does not work from MSIE 3 versions.'),p, submit('post_data',' Submit '),' ',reset.p,endform.end_html;