Attaching a file to email

Please help. I am trying to attach a file to a genererated email.

Here is the relevant HTML form code: and . And I have pasted the relevant CGI code below.

The problems is that the email works fine until the user actually attempts to attach a file. In other words, if the HTML form is filled-out without attaching a file ($WordDoc) then the email is generated and all is well. But if the user, in addition, attaches a file then the CGI script fails.

the CGI code:

open MAIL, "$mailprogram";

print MAIL "To: $recip
print MAIL "From: $from_addr
print MAIL "Subject: $subject

print MAIL "Content-Type: multipart/mixed; boundary=boundarystring

print MAIL "--boundarystring
print MAIL "Content-type: text/html
print MAIL $message;

print MAIL "--boundarystring
print MAIL "Content-Type: application/msword
print MAIL "Content-Transfer-Encoding: base64
print MAIL "Content-Disposition: attachment; filename='TheWordDoc.Doc'";
print MAIL $FORM{$WordDoc};

print MAIL "--boundarystring--";

close MAIL;

Thank you. Peter.


  • In addition: Can I do this without using any additional libraries, like LITE?
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


In this Discussion