Question

My web application creates PDF documents using Zend_Pdf and sends them using Zend_Mail. It also attaches some user uploaded documents (also PDF). The attachments show up in all general used mail programs, except in Apple Mail. The created PDF is about 30 KB and the message is sent using an external mail server.

In Apple Mail the message list shows the message with a paper clip (indicating that it has attachments), but when the message is opened no attachments are visible. When I click 'Details' in the message head, it shows the attachments and the option to save them.

This is the (stripped down) code that sends the e-mail:

<?php
    $mail = new Zend_Mail('utf-8');
    $mail->setFrom('niels@example.com', 'Niels')
         ->setSubject('Subject')
         ->addTo('niels@example.com', 'Niels')
         ->setBodyHtml('Hi there', 'utf-8', Zend_Mime::ENCODING_8BIT);

    $a = new Zend_Mime_Part($pdfContent);
    $a->type = 'application/pdf';
    $a->filename = 'my_pdf.pdf';
    $a->disposition = Zend_Mime::DISPOSITION_ATTACHMENT;
    $a->encoding = Zend_Mime::ENCODING_BASE64;
    $mail->addAttachment($a);

    $mail->setHeaderEncoding(Zend_Mime::ENCODING_BASE64);
    $mail->send();

The mail I receive has the following header for the message

Content-Type: multipart/mixed; boundary="=_f6a669390c6713f60a851af814fe897f"
Content-Disposition: inline
Content-Transfer-Encoding: 7bit
MIME-Version: 1.0

The HTML mail content:

--=_f6a669390c6713f60a851af814fe897f
Content-Type: text/html; charset="utf-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

The attachment content:

--=_f6a669390c6713f60a851af814fe897f
Content-Type: application/pdf
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="my_pdf.pdf"

Is there a way that the attachments show up in the message in Apple Mail? Now some people respond with 'there are no attachments'. Does Apple do some 'smart' things to hide/show the attachments? Or should I use another Content-Disposition etc? I've searched quite some time to find a solution, but am running out of clues.

Was it helpful?

Solution

This is not Zend issue but Apple Mail issue. Install Thunderbird ;-)

Here are few tips:

  • problem like this can occur if you are sending inline files and attachments at the same time
  • mail app settings are defaulted to inline attachments

    1. Close Mail
    2. Open Terminal
    3. enter command defaults write com.apple.mail DisableInlineAttachmentViewing -bool yes,
    4. Open Mail and try again
  • you should not be explicitly specifying encoding in setting body, your mail is initialized with default 'UTF-8' encoding by the way you

  • you should not be encoding header unless you are sending emails in languages that use not Roman letters-based character set

Try attaching the file inline and

$mail = new Zend_Mail('utf-8');
$mail->setFrom('niels@example.com', 'Niels')
         ->setSubject('Subject')
         ->addTo('niels@example.com', 'Niels')
         ->setBodyHtml('Hi there');

// add attachment
$mail->createAttachment(file_get_contents('my_pdf.pdf'), 'application/pdf', Zend_Mime::DISPOSITION_ATTACHMENT , Zend_Mime::ENCODING_BASE64); 

// try sending attachment inline... maybe this will work (not sure if supported by all mail clients)
// $mail->createAttachment(file_get_contents('my_pdf.pdf'), 'application/pdf', Zend_Mime::DISPOSITION_INLINE , Zend_Mime::ENCODING_BASE64); 

$mail->send();

OTHER TIPS

The answer that Alex provided was indeed the solution: it is an Apple Mail issue. When the attachment size increases, it shows up in the e-mail. For example: I just sent a PDF document that is bigger (79KB, shows up as 112KB in the message list) and that is visible. If I send the same kind of PDF (but smaller) it is hidden.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top