src/Mime/Mime.php
public static function encode($body, $encoding, $wrapWidth = 76, $le = "\r\n", $cut = false)
    {
        $encoding = strtolower($encoding);
        switch ($encoding) {
            case 'quoted-printable':
                $body = quoted_printable_encode($body);
                return $wrapWidth ? rtrim(chunk_split($body, $wrapWidth, $le)) : $body;
                break;
            case 'base64':
                $body = base64_encode($body);
                return $wrapWidth ? rtrim(chunk_split($body, $wrapWidth, $le)) : $body;
                break;
            case '7bit':
                if (preg_match('~[^\x00-\x7F]~', $body)) {
                    throw new RuntimeException("Can't use `'{$encoding}'` encoding, non 7 bit characters detected.");
                }
            case '8bit':
            case 'binary':
                $body = ltrim(str_replace("\r", '', $body), "\n");
                return $wrapWidth ? wordwrap($body, $wrapWidth, "\n", $cut) : $body;
                break;
            default:
                throw new InvalidArgumentException("Unsupported encoding `'{$encoding}'`.");
                break;
        }
    }
public static function encode($body, $encoding, $wrapWidth = 76, $le = "\r\n", $cut = false)
    {
        $encoding = strtolower($encoding);
        switch ($encoding) {
            case 'quoted-printable':
                $body = quoted_printable_encode($body);
                return $wrapWidth ? rtrim(chunk_split($body, $wrapWidth, $le)) : $body;
                break;
            case 'base64':
                $body = base64_encode($body);
                return $wrapWidth ? rtrim(chunk_split($body, $wrapWidth, $le)) : $body;
                break;
            case '7bit':
                if (preg_match('~[^\x00-\x7F]~', $body)) {
                    throw new RuntimeException("Can't use `'{$encoding}'` encoding, non 7 bit characters detected.");
                }
            case '8bit':
            case 'binary':
                $body = ltrim(str_replace("\r", '', $body), "\n");
                return $wrapWidth ? wordwrap($body, $wrapWidth, "\n", $cut) : $body;
                break;
            default:
                throw new InvalidArgumentException("Unsupported encoding `'{$encoding}'`.");
                break;
        }
    }
public static function encode ( $ body , $ encoding , $ wrapWidth = 76 , $ le = "\r\n" , $ cut = false ) { $ encoding = strtolower ( $ encoding ) ; switch ( $ encoding ) { case 'quoted-printable' : $ body = quoted_printable_encode ( $ body ) ; return $ wrapWidth ? rtrim ( chunk_split ( $ body , $ wrapWidth , $ le ) ) : $ body ; break ; case 'base64' : $ body = base64_encode ( $ body ) ; return $ wrapWidth ? rtrim ( chunk_split ( $ body , $ wrapWidth , $ le ) ) : $ body ; break ; case '7bit' : if ( preg_match ( '~[^\x00-\x7F]~' , $ body ) ) { throw new RuntimeException ( "Can't use `'{$encoding}'` encoding, non 7 bit characters detected." ) ; } case '8bit' : case 'binary' : $ body = ltrim ( str_replace ( "\r" , '' , $ body ) , "\n" ) ; return $ wrapWidth ? wordwrap ( $ body , $ wrapWidth , "\n" , $ cut ) : $ body ; break ; default : throw new InvalidArgumentException ( "Unsupported encoding `'{$encoding}'`." ) ; break ; } }
Encoding method.

Note: Not relying on `stream_filter_append()` since not stable.

@param  string $body      The message to encode.
@param  string $encoding  The encoding.
@param  string $wrapWidth The wrap width.
@param  string $le        The wrap width line ending.
@return string
Encoding method .