/** * Build attachment for sending * * @return string */ public function build() { $nl = GlobalConstants::NEW_LINE; // Fail if missing data if (is_null($this->content) && is_null($this->path)) { throw new MailAttachmentNoContentException($this->path); } // Extract name from path if (!$this->name && $this->path) { $this->name = basename($this->path); } // Extract mime type from path if (!$this->mime_type && $this->name) { $this->mime_type = Mime::getFromFile($this->name); } // Set Content-Type part header $source = 'Content-Type: ' . $this->mime_type . ($this->name ? '; name="' . $this->name . '"' : '') . $nl; // Set Content-Transfer-Encoding part header if ($this->transfer_encoding) { $source .= 'Content-Transfer-Encoding: ' . $this->transfer_encoding . $nl; } // Set Content-Disposition part header $source .= 'Content-Disposition: ' . $this->disposition . ($this->name ? '; filename="' . $this->name . '"' : '') . $nl; // Set Content-ID part header (for embedded attachments) if ($this->cid) { $source .= 'Content-ID: ' . $this->cid . $nl; } // Get file data $content = $this->content ? $this->content : file_get_contents($this->path); // Encode file data if needed switch ($this->transfer_encoding) { case 'base64': $content = chunk_split(base64_encode($content)); break; } $source .= $nl . $content . $nl; return $source; }
/** * Include favicon */ public static function includeFavicon() { $location = self::favicon(); if (!$location) { return; } echo '<link type="' . Mime::getFromFile($location) . '" rel="icon" href="' . self::path($location) . '" />' . "\n"; }