Return to Snippet

Revision: 49701
at July 28, 2011 07:37 by necode

Initial Code
in magento there is no available methods for attach file. once we do it in magento by adding a following code
in  mage/core/model/email/template.php at the end of file.

public function addAttachment(Zend_Pdf $pdf){
        $file = $pdf->render();
        $attachment = $this->getMail()->createAttachment($file);
        $attachment->type = 'application/pdf';
    $attachment->filename = 'yourfile.pdf';
but i prefer to use Zend_Mail to send mail with attached file.
for this u need to do following.

            $mail = new Zend_Mail();
            $mail->setBodyHtml(" body text"); // here u also use setBodyText options.
            // this is for to set the file format
            $at = new Zend_Mime_Part($content);
            $at->type        = 'application/csv'; // if u have PDF then it would like -> 'application/pdf'
            $at->disposition = Zend_Mime::DISPOSITION_INLINE;
            $at->encoding    = Zend_Mime::ENCODING_8BIT;
            $at->filename    = $filename;
        }catch(Exception $e)
            echo $e->getMassage();

Initial URL

Initial Description
send mail with attached file

Initial Title
Magento Send email easily using Zend_Mail with attached file

Initial Tags
email, magento

Initial Language