I'm using Pears mail mime to send out emails with attachments in php.
http://pear.php.net/package/Mail_Mime/redirected
It seems Outlook is renaming PDF's to "Untitled..." but it works correctly for gmail, hotmail etc.
Prior to this problem I had another problem where Outlook would not show the file as PDF and attach it as text file unless I specifically tell the mime addAttachment the file type
see the code here:
if (endsWith($file,".pdf")) {
$mime->addAttachment($file,'application/pdf',basename($file));
}
else {
$mime->addAttachment($file);
}
You can see above I've also tried setting the 3rd argument of addAttachment to set the filename, but that hasn't worked either.
Outlook does not rename other file types so it's a catch 22 either set no filetype and have Outlook send as txt file or set the filetype and Outlook renames the files to 'Untitled'
ok found out that Outlook doesn't seem to like long filenames, shortening the filename works.
Pear mime sends a long filename header broken up into parts like this:
Content-Transfer-Encoding: base64
Content-Type: application/pdf;
name*0*=US-ASCII''THIDSO5749_010.901%20-%2013.95505142_GARUDA%20RETARGETI;
name*1*=NG%20CPA%20CAMPAIGN_PT%20GARUDA%20INDONESIA%20%28PERSERO%29%20TBK;
name*2*=._NOV2013.pdf
Content-Disposition: attachment;
filename*0*=US-ASCII''THIDSO5749_010.901%20-%2013.95505142_GARUDA%20RETAR;
filename*1*=GETING%20CPA%20CAMPAIGN_PT%20GARUDA%20INDONESIA%20%28PERSERO;
filename*2*=%29%20TBK._NOV2013.pdf;
size=68426
Outlook can't handle this but it can handle the format:
Content-Type: application/pdf;name="a long filename.....pdf"
Unfortunately it seems Pear mime can't send this format without editing the core code of mime.php
So I'm just sending shorter filenames for now
Related
I want to attach a MTA report (not delivered bounce mail) to an email, but what is the correct MIME type?
I fetch the full body of the MTA report with
$body = imap_fetchbody($this->Mailbox->stream, $this->header->uid, '', FT_UID);
But what is the correct MIME type for attached .eml files?
Have tried message/rfc822 but when you open the file in Thunderbird the popup windows is empty. Have also tried text/plain but then the attachment is opended as plain text. I want to open the attachment .eml as an email
When you receive a MTA report (not delivered) the bounce mail is always forwarded as an attachment
I want to attach the full MTA report + forwarded bounce mail to a new mail
Content-Type: application/octet-stream should do the trick.
Our (proprietary) mail client at work just sets Content-Type: application/octet-stream; name="xxx.EML" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="xxx.EML", and is able to open the received attachment “as” an email again via double click. Since that mime type is anything but specific, I suppose it falls back onto the file type handler registered for the .eml suffix on the OS level.
message/rfc822 ("encapsulated message") works, at least with ReactDropzone. That string is what's reported as Type when an .eml file is dropped. (YMMV.)
There is no mime type for it based on list as of 2020-12-23. See:
http://www.iana.org/assignments/media-types/media-types.xhtml
I'm trying to send two or three attachments via phpMailer.
The mail itself sends perfectly when only text or a small attachment, but when I attach 2 pdf's that are (i think) bigger than 1mb total the mail gets garbled, the boundaries are messed up. The data of the file is attached if I look in the source, so that is not the problem.
It occurs when using mail() and isSMTP(). I've set the limits to >256 mb. The file allready exists on the disk (no post/get), I use the base url (/home/user/domain/public_html/file.pdf)
Any ideas? Below example of start of the headers of the mail.
--b1_6166a1a8c31cfb63964d1ce6fac035a7
Content-Type: multipart/alternative;
boundary="b2_6166a1a8c31cfb63964d1ce6fac035a7"
--b2_6166a1a8c31cfb63964d1ce6fac035a7
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
edit: The calls $mailer->AddAttachment(...) are being done as last calls just before the send() function.
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.
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
Close Mail
Open Terminal
enter command defaults write com.apple.mail DisableInlineAttachmentViewing -bool yes,
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();
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.
I have a web application that builds a dynamic PDF with FPDF and allows you to download it. That works fine. When I try to email it to myself as a test instead of downloading, I get an email with a corrupt PDF attachment.
I have tried the code from http://www.astahost.com/info.php/create-email-pdf-file-39on-fly39-php_t6334.html and http://www.daniweb.com/code/snippet217105.html but get the same result each time.
Has anyone come across this or know a way to fix it?
Your best way to get help here is to subset the full text headers and body of a received message, and place them in your question. Email is encoded, and not all email servers pass all types of encoding. The code you're using specifies "Content-Transfer-Encoding: base64".
Here's a valid JPG encoded with same:
--_eba07140-496e-4f3d-91ce-aff8afde8879_
Content-Type: image/jpeg
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="DSC03538_AZ_atCape.JPG"
/9j/4Rt/RXhpZgAASUkqAAgAAAALAA4BAgAgAAAAkgAAAA8BAgAFAAAAsgAAABABAgAHAAAAuAAA
ABIBAwABAAAAAQAAABoBBQABAAAAwAAAABsBBQABAAAAyAAAACgBAwABAAAAAgAAADIBAgAUAAAA
....
I have a php script that will an catch email passed to it and process it.
#!/usr/local/bin/php -q
<?php
while (!feof(STDIN)) {$s .= fgets(STDIN);}
// Now do some work on the email source in $s.
?>
This works fine. My question is how to save an attachment into the file system from the source. For example, if I isolate the section below, how do I need to process it before saving it into a gif file to create a valid gif?
I assume I need to change the encoding, or otherwise process it, but does anyone know exactly?
Thanks!
--------------090607000609050308090504
Content-Type: image/gif;
name="tfk.gif"
Content-Transfer-Encoding: base64
Content-ID: <part1.06050801.05020504#etc....>
Content-Disposition: attachment;
filename="tfk.gif"
R0lGODlheAA8APcAAAAAAP/////Wgv+xEgliOAEcDxAnFiAyHTA+JEBKK0BKLFBWM2BhOv//
nf//tfz60dDEPdnPT//0Z3BtQf/kBv/pKM/KoO3UHendgoB5SOTGB/HSCNm8D7+oEvrhRcW1
U+visL2dA3hlAqqNBM+vB52DBo+ET4+EUJp+AnNgCmdUCZV9EredLJuKQ4x9PVNCBo1yC39n
C6OG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aRJ++qeMGvoRi9qokKoRjxqplFo0EHGpmJqpmrqpCBEQADs=
--------------090607000609050308090504--
Mailparse
Try the PEAR_Mail_MimeDecode class from Pear. You can feed it the entire mail, and get back the various MIME chunks... and no need to install an extension.
For a PHP solution (no C extensions required), there's PEAR Mail_mimedecode.
After parsing the e-mail, you already have the attachment bytestream, no need to base64 decode yourself.