示例#1
0
 /**
  * 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="' . String::fixEncoding(basename($file)) . '"');
     return $this->attachments[] = $part;
 }
示例#2
0
	/**
	 * Creates file MIME part.
	 * @return MailMimePart
	 */
	private function createAttachment($file, $content, $contentType, $disposition)
	{
		$part = new MailMimePart;
		if ($content === NULL) {
			if (!is_file($file)) {
				throw new \FileNotFoundException("File '$file' not found.");
			}
			if (!$contentType && $info = getimagesize($file)) {
				$contentType = $info['mime'];
			}
			$part->setBody(file_get_contents($file));
		} else {
			$part->setBody((string) $content);
		}
		$part->setContentType($contentType ? $contentType : 'application/octet-stream');
		$part->setEncoding(preg_match('#(multipart|message)/#A', $contentType) ? self::ENCODING_8BIT : self::ENCODING_BASE64);
		$part->setHeader('Content-Disposition', $disposition . '; filename="' . String::fixEncoding(basename($file)) . '"');
		return $part;
	}
示例#3
0
	/**
	 * Creates file MIME part.
	 * @return MailMimePart
	 */
	private function createAttachment($file, $content, $contentType, $disposition)
	{
		$part = new MailMimePart;
		if ($content === NULL) {
			$content = file_get_contents($file);
			if ($content === FALSE) {
				throw new \FileNotFoundException("Unable to read file '$file'.");
			}
		} else {
			$content = (string) $content;
		}
		$part->setBody($content);
		$part->setContentType($contentType ? $contentType : Nette\Tools::detectMimeTypeFromString($content));
		$part->setEncoding(preg_match('#(multipart|message)/#A', $contentType) ? self::ENCODING_8BIT : self::ENCODING_BASE64);
		$part->setHeader('Content-Disposition', $disposition . '; filename="' . String::fixEncoding(basename($file)) . '"');
		return $part;
	}