/** * Creates file MIME part. * @param string * @param string * @param string * @return MailMimePart */ public function createFilePart($file, $contentType, $encoding) { if (!is_file($file)) { throw new FileNotFoundException("File '{$file}' not found."); } if (!$contentType) { $info = getimagesize($file); $contentType = $info ? image_type_to_mime_type($info[2]) : 'application/octet-stream'; } $part = new MailMimePart(); $part->setContentType($contentType); $part->setEncoding($encoding); $part->setBody(file_get_contents($file)); return $part; }
/** * Adds attachment. * @param string * @param string * @param string * @return MailMimePart */ public function addAttachment($file, $content = NULL, $contentType = NULL) { $part = new MailMimePart(); $part->setBody($content === NULL ? $this->readFile($file, $contentType) : (string) $content); $part->setContentType($contentType ? $contentType : 'application/octet-stream'); $part->setEncoding(self::ENCODING_BASE64); $part->setHeader('Content-Disposition', 'attachment; filename="' . basename($file) . '"'); return $this->attachments[] = $part; }
/** * Returns encoded message. * @return string */ public function generateMessage() { if ($this->getHeader('Message-ID')) { return parent::generateMessage(); } else { return $this->build()->generateMessage(); } }