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

Hi Monks, I am trying to make this code to get some parameters from a form and attach a file to it and e-mail it to me from my website but I can't get it to work, any help??
Here is the code

#!/usr/bin/perl use CGI; 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')); if ($filename ne ""){ $tmp_file = $q->tmpFileName($filename); } $sender = new Mail::Sender {from => '$email',smtp => 'myhost.temp.host +ing.com'}; $sender->OpenMultipart({to=> 'myself@mysite.com',subject=> '$position' +}); $sender->Body(); $sender->Send(<<"*END*"); This is just a test of mail with an uploaded file. This is a test. *END* $sender->SendFile( {encoding => 'Base64', description => $filename, ctype => $q->uploadInfo($filename)->{'Content-Type'}, disposition => "attachment; filename = $filename", file => $tmp_file }); $sender->Close(); print "Content-type: text/plain\n\n"; print "Yes, it's sent\n\n"; # remove security rish charactors from the data extracted from the url 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/\%2F//g; return $_[0]; }


I know I am not on a Unix server....

Thank you!

Replies are listed 'Best First'.
Re: Mail Sender Problem
by iburrell (Chaplain) on Jan 27, 2004 at 19:16 UTC
    "Can't get it to work" does not help us or you try to figure out what the problem is. What isn't working? What error messages are you getting? Have you tried turning on debugging?

    It looks like you aren't checking the return codes from the methods. By default, Mail::Sender functions return undef on failures. It supports die'ing instead on errors which saves having to check every method. Also, it supports printing out debugging messages to a file or STDOUT.

    my $sender = Mail::Sender->new({ on_errors => 'die', debug => \*STDOUT });
Re: Mail Sender Problem
by gmpassos (Priest) on Jan 27, 2004 at 19:47 UTC
    Well, you can take a look at Mail::SendEasy.

    Note that you need to know if your SMTP server works, and if it needs authentication.

    Mail::SendEasy will be able to handle all your needs, STMP, authentication and attachments.

    About the SMTP server, generally we use the localhost SMTP server, since generally it won't ask for authentication, and it enables you to send e-mails from your domain. Note that you can't use any SMTP server to send e-mail from any domain. Soo, if your "from" e-mail is "foo@x.com", your SMTP server need to let you send e-mails for the domain "x.com".

    If this doesn't work for you, you still can talk with your Web Hoster.

    Graciliano M. P.
    "Creativity is the expression of the liberty".

Re: Mail Sender Problem
by gothic_mallard (Pilgrim) on Jan 27, 2004 at 15:23 UTC

    You don't really state exactly what you mean by "can't get it to work" - if you're having trouble with the Mail::Sender module you could always try my JMailer module that you can check out here

    It's a nice simple interface to Net::SMTP that allows for HTML / plain encoding and multiple attachments with a lot less grief than Mail::Sender may cause the unweary user :-)