I'm trying to send a file via Zend Framework's (1.10.7) Mail library.
$mail = new Zend_Mail();
$mail->setSubject('Test');
$mail->setFrom('hello@ex.com');
$mail->setBodyText ( "" );
$at = $mail->createAttachment($txtFile->toString(),
'text/plain',
Zend_Mime::DISPOSITION_ATTACHMENT,
Zend_Mime::ENCODING_8BIT);
$mail->addTo ( "hi@you.com" );
$mail->send();
The file is a simple text file. It works with Outllok, I receive a proper attachment but not with Gmail and Lotus Notes.
With Gmail I have this message :
This is a message in Mime Format. If you see this, your mail reader does not support this format.开发者_如何学Python
Lotus Notes says this :
MIME content for this item is stored in attchment $RFC822.eml. Parsing MIME content failed: Incorrect format in MIME data..
What's wrong with Zend's Mail attachments ?
The docs say that the first parameter should be a binary string of data that is being sent.
Some of the comments suggest using file_get_contents()
for sending an image, this of course does return a string, but it is a string of binary data that represent the image.
What does your toString()
method return for the $txtFile
? A simple string like
return "This is some plain text";
or does it return binary data?
You might want to try creating a plain text file with some content, then using file_get_contents()
on that file and using the return value as the first parameter for sending the attachment, rather than just sending it a plain string.
Hope that helps.
Apparently it was our anti-spam software that was messing with the email's headers (in output).
精彩评论