Zend_Mail::createAttachment PHP Method

createAttachment() public method

Attachment is automatically added to the mail object after creation. The attachment object is returned to allow for further manipulation.
public createAttachment ( string $body, string $mimeType = Zend_Mime::TYPE_OCTETSTREAM, string $disposition = Zend_Mime::DISPOSITION_ATTACHMENT, string $encoding = Zend_Mime::ENCODING_BASE64, string $filename = null ) : Zend_Mime_Part
$body string
$mimeType string
$disposition string
$encoding string
$filename string OPTIONAL A filename for the attachment
return Zend_Mime_Part Newly created Zend_Mime_Part object (to allow advanced settings)
    public function createAttachment($body, $mimeType = Zend_Mime::TYPE_OCTETSTREAM, $disposition = Zend_Mime::DISPOSITION_ATTACHMENT, $encoding = Zend_Mime::ENCODING_BASE64, $filename = null)
    {
        $mp = new Zend_Mime_Part($body);
        $mp->encoding = $encoding;
        $mp->type = $mimeType;
        $mp->disposition = $disposition;
        $mp->filename = $filename;
        $this->addAttachment($mp);
        return $mp;
    }

Usage Example

Example #1
0
 public static function sendExceptionByMail(Exception $e, $from, $to)
 {
     // generate mail datas
     $subject = '[' . MAIN_URL . ':' . CONFIG_ENV . '] Exception Report: ' . wordlimit_bychar($e->getMessage(), 50);
     $body = $e->getMessage() . ' in ' . $e->getFile() . ' at line ' . $e->getLine();
     // sned mail throw Zend_Mail
     $mail = new Zend_Mail();
     $mail->setSubject($subject)->setFrom($from)->setBodyText($body);
     $emails = explode(' ', $to);
     foreach ($emails as $email) {
         $mail->addTo($email);
     }
     $att = $mail->createAttachment(var_export($_GET, true), Zend_Mime::TYPE_TEXT);
     $att->filename = 'GET.txt';
     $att = $mail->createAttachment(var_export($_POST, true), Zend_Mime::TYPE_TEXT);
     $att->filename = 'POST.txt';
     // send session dump only if exists
     if (session_id() != null) {
         $att = $mail->createAttachment(var_export($_SESSION, true), Zend_Mime::TYPE_TEXT);
         $att->filename = 'SESSION.txt';
     }
     $att = $mail->createAttachment(var_export($_SERVER, true), Zend_Mime::TYPE_TEXT);
     $att->filename = 'SERVER.txt';
     $att = $mail->createAttachment($e->getTraceAsString(), Zend_Mime::TYPE_TEXT);
     $att->filename = 'backtraceExeption.txt';
     $mail->send();
 }
All Usage Examples Of Zend_Mail::createAttachment