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.
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 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
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 am generating images dynamically at run time with php and have them displayed in base 64 through the browser.
This same page/html document I need emailed but this method to show images does not work through email.
I have found two code igniter libraries to try and help me with this task two of which do not work
http://thecodeabode.blogspot.com/2010/11/codeigniter-and-php-howto-embedding.html
http://codeigniter.com/wiki/Richmail/
The first one gives me
Unable to send email using PHP mail().
Your server might not be configured to
send mail using this method.
From: "SystemDDX" Return-Path:
Reply-To: "internal-33e#google.com"
X-Sender: internal-33ek#google.com
X-Mailer: CodeIgniter X-Priority: 3
(Normal) Message-ID:
<1d42c5c99deeb#google.com>
Mime-Version: 1.0 Content-Type:
text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
The second one is extremely outdated
The only method which I've managed to get working so far is using the code igniter
$this->email->attach("C:\myfile.jpg")
and then in my html reference using <img src='cid:myfile.jpg' />
The problem is my image is in base64 as I'm generating it dynamically so if I can't figure out anything else, how can I revert base 64 to a specific file name while keeping it in memory.
Please any tips and help would be greatly appreciated
The only method which I've managed to get working so far is ... <img src='cid:myfile.jpg' />
Good, because that's the way it should be done. As you have discovered, inlined base64 images are very poorly supported outside of bleeding-edge browsers.
The problem is my image is in base64 as I'm generating it dynamically so if I can't figure out anything else, how can I revert base 64 to a specific file name while keeping it in memory.
Well, how are you converting that image to base64 to begin with? You're certainly using base64_encode on the image's data, right?
Well then, don't do that!
Instead, write the image data to a new file on disk, and then reference that new image file when attaching it to the outgoing mail. Problem solved!
This assumes that the attachment method in your chosen email library only accepts real files -- read the docs, I'll bet that you can pass the image data directly and give it a "fake" file name at the same time.
You might want to consider using another modern mail library, like SwiftMailer. It can attach dynamic content smoothly and easily.
I'm generating sparklines graphics dynamically and using this to get the content:
function OutputToDataURI() {
ob_start(NULL,4096);
$this->Output();
header('Content-type: text/html');
return "data:image/png;base64,".base64_encode(ob_get_clean());
}
In that case, this will get your raw image data:
public function GetImageData() {
ob_start();
$this->Output();
return ob_get_clean();
}
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
....