So, there was 2 mistakes... First, the type is not the MIME type of your
uploaded document : it's always an  'application/octet-stream', even for
plain text (because of \r\n, etc.). By consequence, you've to change the
encoding too : base 64.

        $attachment = new
Zend_Mime_Part(file_get_contents($form->attachment->getFileName()));
        $attachment->type        = 'application/octet-stream';
        $attachment->disposition = Zend_Mime::DISPOSITION_INLINE;
        $attachment->encoding    = Zend_Mime::ENCODING_BASE64;
        $attachment->filename    = $infos['attachment']['name'];


On Mon, Oct 19, 2009 at 3:55 PM, Thomas VEQUAUD <[email protected]>wrote:

> Hi there,
>
> I try to attach an Excel file to a mail via Zend_Mail... That works...
> Document attached. But once downloaded : cannot open the document because of
> a corrupted content. So, I suppose the issue comes from the PHP function
> file_get_contents.
>
> // Attachment
> $infos = $form->attachment->getFileInfo();
>  $attachment = new
> Zend_Mime_Part(file_get_contents($form->attachment->getFileName()));
>  $attachment->type        = $form->attachment->getType();
>  $attachment->disposition = Zend_Mime::DISPOSITION_INLINE;
>  $attachment->encoding    = Zend_Mime::ENCODING_8BIT;
> $attachment->filename    = $infos['attachment']['name'];
>
> // Send Email
> $mail = new Zend_Mail(APPLICATION_ENCODING);
>  $mail->addAttachment($attachment);
>
> I'm sure somebody met that problem before...
>  --
> Thomas VEQUAUD          http://thomas.vequaud.free.fr/
> Expert EPITECH en Ingénierie Informatique
> Tél : +33(0)6.50.39.28.10  Fax: +33(0)9.58.46.10.07
>
>
>


-- 
Thomas VEQUAUD          http://thomas.vequaud.free.fr/
Expert EPITECH en Ingénierie Informatique
Tél : +33(0)6.50.39.28.10  Fax: +33(0)9.58.46.10.07

Reply via email to