
To retrieve an IHeader object, call IMessage::getHeader() from a ZBateson\MailMimeParser\IMessage object.
GenericHeader is used for any other header. SubjectHeader for Subject headers (basically just mime-header decoding). ReceivedHeader for Received header parsing. IdHeader for ID headers, like Message-ID, Content-ID, In-Reply-To and Reference. ParameterHeader represents headers consisting of multiple name/values (e.g. DateHeader parses header values into a DateTime object (e.g. AddressHeader is returned for headers consisting of addresses and address groups (e.g. $parser = new MailMimeParser () // parse() returns an IMessage $message = $parser -> parse ( $resource, true ) // alternatively: // $string = 'an email message to load' $message = Message :: from ( $string, false ) Message headersĪnd sub-classes, depending on the type of header being parsed. Use ZBateson\MailMimeParser\MailMimeParser use ZBateson\MailMimeParser\Message // $resource = fopen('my-file.mime', 'r') //. It accepts the same arguments as parse(). The parse() method accepts a string, resource handle, or Psr7 StreamInterfaceĪlternatively for procedural/non dependency injected usage, calling Object as a dependency to your class, and call To parse an email using zbateson/mail-mime-parser, pass a PSR-compliant, unit and functionally tested.įor the 1.0 usage guide, click here Parsing an email. Uses streams internally to avoid keeping everything in memory. Multipart/signed (signing functionality not included… the library canĬonvert the message and provide the part of the message that needs to be Multipart/alternative or mixed, add/remove attachments, set the message as Can edit a message by setting headers, overwriting content, changing to/from. Without the attachments is also very fast. As of 2.0, parses parts of a message on-demand, so reading the subject lineįrom a very large message can be very fast, or reading just the text body. As of 1.0, can handle multiple headers of the same name (unlike mailparse or. GetHeader(), rather than a confusing array posing as an object. Parses messages into a Message object with handy methods like getContent(),. Supports all of RFC-5322, RFC-2822 and RFC-822, and tries to be as forgivingĪs possible for incorrectly formatted messages. No need to worryĪbout whether the content is base64 encoded and using WINDOWS-1256 charsetĮncoding (so long as mb_* or iconv* support the charset, or I’ve identified Handles content decoding and charset conversion for you. Users rely on regex patterns to decode parts of a header, and end up ignoring No need to worry about theįormat a header is in, if it’s RFC2047 or RFC2231, contains nested comments,Įmail lists, multiple lines, or combinations thereof. Handles header decoding/charset/formats for you. There are numerous advantages over other libraries: It does not use PHP’s imap* functions or the pecl mailparse There’s no need to worry about the Content-Transfer-Encoding, or how the name inĪn email address is encoded, or what charset was used.Īnd, unlike most other available email parsing libraries, MailMimeParser is its Use ZBateson\MailMimeParser\Message $message = Message :: parse ( $handleOrStreamOrString, true ) $subject = $message -> getHeaderValue ( 'Subject' ) $text = $message -> getTextContent () $html = $message -> getHtmlContent () $from = $message -> getHeader ( 'From' ) $fromName = $from -> getName () $fromEmail = $from -> getEmail () $to = $message -> getHeader ( 'To' ) // first email address can be accessed directly $firstToName = $to -> getName () $firstToEmail = $to -> getEmail () foreach ( $to -> getAllAddresses () as $addr ) $attachment = $message -> getAttachmentPart ( 0 ) $fname = $attachment -> getFilename () $stream = $attachment -> getContentStream () $attachment -> saveContent ( 'destination-file.ext' )