views:

59

answers:

1

Hi,

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('[email protected]');
$mail->setBodyText ( "" );

$at = $mail->createAttachment($txtFile->toString(), 
                                'text/plain', 
                                Zend_Mime::DISPOSITION_ATTACHMENT, 
                                Zend_Mime::ENCODING_8BIT);
$mail->addTo ( "[email protected]" );                              
$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.

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 ?

A: 

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.

jakenoble
$txtFile->toString() returns a string and it works with Outlook. I have a file attached in Outlook.
kevin
Regardless, have you tried my method of file_get_contents? Outlook is Microsoft which makes it a special case, which makes it a bad test/benchmark. Remember a smilie in Outlook is a J on all other mail clients. With that of behaviour you could send it anything and it might accept/render it!
jakenoble
I have the same results with file_get_contents
kevin