email attachments - doc file


N

Nara Bala

Hi,
I am doing a cgi script through which the client attaches a file on
the local machine and submits a form, upon which the file is uploaded
to an unix-based server and emailed using sendmail as an attachment.
I am able to send ordinary text files successfully. But when I try
doing it for word documents. The file is attached and sent. But when I
recieve it, the file is slighlty largerthan the original file and it
doesnt open in Word. The word throws an error saying "The document
name or path is not valid....". I tried saving the file to local
machine and then opening still i have the same problem.
Pls. let me know what mistake I am making.
Look at this code -


#!/usr/bin/perl
use CGI;
use CGI qw:)standard);
require 'CGI_LIB.pl';

my $sendmail = "/usr/lib/sendmail -t";
my $filename = "/srcm/smsf/temp/uploadedFile.txt";
&Parse_Multi;
binmode($CGI);
open(SENDMAIL, "|$sendmail") or die "Cannot open $sendmail: $!";
print SENDMAIL <<"EOF";
Content-Transfer-Encoding: 7bit
Content-Type: multipart/mixed; boundary="=_3D647253.85E4AEC4"
MIME-Version: 1.0
Date: Thu, 21 Mar 2002 19:32:35 UT
From: nara\@hotmail.com
To: narayananb\@ami.com
Subject: Testing File Attachments - quoted printable
This is a MIME message. If you are reading this text, you may want to
consider changing to a mail
reader or gateway that understands how to properly handle MIME
multipart messages.

--=_3D647253.85E4AEC4
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Test from Shane
Hello World

--=_3D647253.85E4AEC4
Content-Description: "$filename"
Content-Type: $CGI{'UploadedFile'}->{'Content-Type'};
charset=iso-8859-1
Content-Disposition: attachment; filename="file_name.doc"

$CGI{'UploadedFile'}->{'Contents'}
--=_3D647253.85E4AEC4--
EOF

close(SENDMAIL) or warn "sendmail did not close nicely";

$url = "/others/feedback-thanks.html";
print "Location: $url\n\n";

# end of code
exit;




thanks,
Nara
 
Ad

Advertisements

T

Tintin

Nara Bala said:
Hi,
I am doing a cgi script through which the client attaches a file on
the local machine and submits a form, upon which the file is uploaded
to an unix-based server and emailed using sendmail as an attachment.
I am able to send ordinary text files successfully. But when I try
doing it for word documents. The file is attached and sent. But when I
recieve it, the file is slighlty largerthan the original file and it
doesnt open in Word. The word throws an error saying "The document
name or path is not valid....". I tried saving the file to local
machine and then opening still i have the same problem.
Pls. let me know what mistake I am making.
Look at this code -


#!/usr/bin/perl

Where's the:

use strict;
use CGI;
use CGI qw:)standard);

No need/use/point in trying to use the CGI module twice.
require 'CGI_LIB.pl';

Why use another CGI module, surely one is enough?
my $sendmail = "/usr/lib/sendmail -t";
my $filename = "/srcm/smsf/temp/uploadedFile.txt";
&Parse_Multi;

Why are you using the & for the function call?

[snipped a whole bunch of hardcoded MIME encoding that would be much better
done using the MIME::Lite module]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top