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

What is the easiest way to send virtually any kind of file attachment via a form? Please don't direct me to the super search, I've read all of them and none of them help my problem.

I want to have an upload field in my cgi form then from this have that file attach be sent with the email regardless of the file type. Even if you have to specifiy the file type first I still want to know how to do this via a form, all the examples were paths to files already on the server.

Any help would be much appreciated.

Replies are listed 'Best First'.
Re: attaching files from a web-based form
by dorko (Prior) on Apr 11, 2003 at 00:24 UTC
    Let me start by saying I don't have an answer to your problem.

    From your research, you know how to (A) send an attachment if it's already a file on the server. If you can learn how to (B) use a form to save a file to your server, then you can use (B) + (A) to do what you're looking for.

    (Demonstrate to the Monastery a good faith effort that you have tried and failed to do this on your own, and odds are, you'll get some better help. (i.e. show some code...))


    -- Yeah, I'm a Delt.

    Update: a Super Search on "mail attachment form" lead me to this thread, including the ubiquitous pointer from merlyn to one of his columns.

      After reading up on everything all I could figure out was how to save things to the server and use them then. If that were my goal I wouldn't have had to ask help, I'd rather have a form upload send files on the fly rather than having an external program to upload files and another to send the with. I will take a look at the thread you posted, thanks dorko.
        I don't think it's possible to not save the file at least temporarily before emailing. In any case, you can upload the file, save it, email it, and delete it all in one script. You wouldn't need to have multiple programs.
Re: attaching files from a web-based form
by Jenda (Abbot) on Apr 11, 2003 at 12:28 UTC

    Mail::Sender's docs contain an example.

    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
       -- Rick Osborne

    Edit by castaway: Closed small tag in signature

•Re: attaching files from a web-based form
by merlyn (Sage) on Apr 11, 2003 at 13:08 UTC