src/Mail/Message.php
private function createAttachment(
        string $file,
        string $content = null,
        string $contentType = null,
        string $disposition
    ): MimePart {
        $part = new MimePart;
        if ($content === null) {
            $content = @\file_get_contents($file); // @ is escalated to exception
            if ($content === false) {
                throw new FileNotFoundException("Unable to read file '$file'.");
            }
        }

        if (!$contentType) {
            $contentType = MimeType::getMimeTypeByContent($content);
        }

        if (!\strcasecmp($contentType, 'message/rfc822')) { // not allowed for attached files
            $contentType = 'application/octet-stream';
        } elseif (!\strcasecmp($contentType, 'image/svg')) { // Troublesome for some mailers...
            $contentType = 'image/svg+xml';
        }

        $part->setBody($content);
        $part->setContentType($contentType);
        $part->setEncoding(\preg_match('#(multipart|message)/#A', $contentType) ?
            self::ENCODING_8BIT : self::ENCODING_BASE64);
        $part->setHeader('Content-Disposition',
            $disposition . '; filename="' . Strings::fixEncoding(\basename($file)) . '"');

        return $part;
    }
private function createAttachment(
        string $file,
        string $content = null,
        string $contentType = null,
        string $disposition
    ): MimePart {
        $part = new MimePart;
        if ($content === null) {
            $content = @\file_get_contents($file); // @ is escalated to exception
            if ($content === false) {
                throw new FileNotFoundException("Unable to read file '$file'.");
            }
        }

        if (!$contentType) {
            $contentType = MimeType::getMimeTypeByContent($content);
        }

        if (!\strcasecmp($contentType, 'message/rfc822')) { // not allowed for attached files
            $contentType = 'application/octet-stream';
        } elseif (!\strcasecmp($contentType, 'image/svg')) { // Troublesome for some mailers...
            $contentType = 'image/svg+xml';
        }

        $part->setBody($content);
        $part->setContentType($contentType);
        $part->setEncoding(\preg_match('#(multipart|message)/#A', $contentType) ?
            self::ENCODING_8BIT : self::ENCODING_BASE64);
        $part->setHeader('Content-Disposition',
            $disposition . '; filename="' . Strings::fixEncoding(\basename($file)) . '"');

        return $part;
    }
private function createAttachment ( string $ file , string $ content = null , string $ contentType = null , string $ disposition ) : MimePart { $ part = new MimePart ; if ( $ content === null ) { $ content = @ \ file_get_contents ( $ file ) ; // @ is escalated to exception if ( $ content === false ) { throw new FileNotFoundException ( "Unable to read file '$file'." ) ; } } if ( ! $ contentType ) { $ contentType = MimeType :: getMimeTypeByContent ( $ content ) ; } if ( ! \ strcasecmp ( $ contentType , 'message/rfc822' ) ) { // not allowed for attached files $ contentType = 'application/octet-stream' ; } elseif ( ! \ strcasecmp ( $ contentType , 'image/svg' ) ) { // Troublesome for some mailers... $ contentType = 'image/svg+xml' ; } $ part -> setBody ( $ content ) ; $ part -> setContentType ( $ contentType ) ; $ part -> setEncoding ( \ preg_match ( '#(multipart|message)/#A' , $ contentType ) ? self :: ENCODING_8BIT : self :: ENCODING_BASE64 ) ; $ part -> setHeader ( 'Content-Disposition' , $ disposition . '; filename="' . Strings :: fixEncoding ( \ basename ( $ file ) ) . '"' ) ; return $ part ; }
Creates file MIME part.

@param string      $file
@param string|null $content
@param string|null $contentType
@param string      $disposition

@return MimePart
Creates file MIME part .