Attaching PDFs
I'm trying to attach files using the code from the example on this site. The attachments go through correctly if the attachment is an image or a text file, but I can not get a PDF or Word document to go through. I receive the following error: malformed json response: malformed JSON string, neither array, object, number, string or atom, at character offset 0 (before "\r\n
<tit...") at /usr/share/perl5/vendor_perl/JSON.pm line 171.Is there a trick to attaching a PDF?
Hi there Eddie,
I have tried sending PDF attachments in the following methods:
$mime->attach(Path => $path, Filename => $ filename, Type => 'application/pdf', Disposition => 'attachment', ) or die "Error adding file!";
and
my $my_file_txt = 'test.txt'; $mime->attach ( Path => $my_file_txt, Type => 'text/txt', Encoding => 'base64' ) or die "Error adding !\n";
but both methods failed to deliver the PDF correctly. The first one sent a corrupted PDF, and the second one didn't send an attachment at all.
Could you give us an idea on this please?
Thanks!
Hi Victor,
I sent through a query for this a few days ago. I played around a little and got the following code to work. "Disposition" is required, in my opinion. I used to get corrupt PDF files as well, but using a path from same or child directories seemed to work.
$mime->attach(Path => $path, Filename => $filename, Type => '-SUGGEST', Disposition => 'attachment', );
Hope this helps.
Gaurav