Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi there!!

My code below works, well it works till I got the file attached that comes in empty. I just can't figure it out what is causing it to be empty. Can anyone look at this and please let me know what I am not seeing it? I am using the right stuff on the html form

...METHOD="post" ENCTYPE="multipart/form-data"

, but it's got to be something else that I can't see, please help.....
Here is the code
use CGI qw(:standard); use CGI::Carp qw(fatalsToBrowser); use Mail::Sender; $q = new CGI; # uploading the file... my $position = &filter($q->param('position')); my $name = &filter($q->param('name')); my $email = &filter($q->param('email')); my $filename = &filter($q->param('filename')); print header(); if ($filename ne ""){ $tmp_file = $q->tmpFileName($filename); }else{$filename= "No Attachment";} ref ($sender = new Mail::Sender({from =>$email,smtp=> 'mytest.temp.hos +ting.com'})) or die "$Mail::Sender::Error\n"; (ref ($sender->MailFile( {to =>'thetester@test.com', cc=>'mytest@test.com',subject =>$positio +n, msg => "Hi.\nI'm sending you the pictures you wanted.", file => $filename })) and print "Mail sent OK." ) or die "$Mail::Sender::Error\n"; sub filter { $_[0]=~s/\'/\\\'/g; $_[0]=~s/<//g; $_[0]=~s/>//g; $_[0]=~s/;//g; $_[0]=~s/\(//g; $_[0]=~s/\)//g; $_[0]=~s/\"//g; $_[0]=~s/\'//g; $_[0]=~s/\?//g; $_[0]=~s/script//g; $_[0]=~s/\///g; $_[0]=~s/>//g; $_[0]=~s/@/\@/g; #$_[0]=~s/\%2F//g; return $_[0]; } __END__

Thanks!

Edit by BazB: add readmore tags

Replies are listed 'Best First'.
Re: Email attachment help!
by Coruscate (Sexton) on Jan 27, 2004 at 21:22 UTC

    I'm going to guess that you should be passing $tmp_file to Mail::Sender (as Mail::Sender wants the path to the file on your server, not the filename from the client's machine).

Re: Email attachment help!
by bassplayer (Monsignor) on Jan 27, 2004 at 21:28 UTC
    Hi,

    I've never used Mail::Sender before, but I have used MIME::Lite to send attachments before and can recommend it. It's quite easy to use. Not sure if that fits in with your project and requirements, but I thought I'd mention it.

    bassplayer

Re: Email attachment help!
by bobn (Chaplain) on Jan 28, 2004 at 00:38 UTC
    If Mail::Sender is to be handed a file, then the file needs to be on the server. So you need to provide the whole path of the file on the server. If you mean to allow the web user to send a file from his machine, you'll need a 2 step process, where you upoload the file from cleint to server, then give MailFile the name of the file on the server.

    --Bob Niederman, http://bob-n.com

    All code given here is UNTESTED unless otherwise stated.