azjezz/psl
PSL is a modern, well-typed standard library for PHP 8.4+, inspired by HHVM’s HSL. It offers safer, predictable APIs for async, collections, networking, I/O, crypto, terminal UI, and robust data validation—replacing brittle built-ins with consistent alternatives.
The Message component implements RFC 5322 Internet Message construction, parsing, and serialization. It provides typed access to standard header fields (From, To, Subject, Date, Message-ID, etc.) with the message body represented as a MIME PartInterface.
Messages are built using the fluent with*() methods. Each returns a new immutable instance. Address methods (withFrom, withTo, withCc, withBcc, withReplyTo) accept a plain string, a Mailbox, or an AddressList.
@example('protocols/message-construct.php')
The message body is a PartInterface from the MIME component. Compose any MIME structure using Part\Text, Part\Data, and the multipart types.
@example('protocols/message-multipart.php')
serialize() produces a streaming RFC 5322 representation. parse() accepts a string or a ReadHandleInterface for streaming input from network sockets.
@example('protocols/message-serialize-parse.php')
Factory methods derive threading headers (In-Reply-To, References) and address fields from an original message per RFC 5322.
@example('protocols/message-reply.php')
Envelope derives the transport-level sender (MAIL FROM) and recipients (RCPT TO) from message headers per RFC 5321. These may differ from the visible From/To/Cc headers.
@example('protocols/message-envelope.php')
The Address namespace provides RFC 5322 compliant address parsing:
Mailbox represents a single email address with optional display name and RFC 5322 commentsGroup represents a named group of mailboxes (display-name : mailbox-list ;)AddressList holds an ordered list of mailboxes and groups, with merge and exclude operationsAll address types support RFC 2047 encoded-word display names for non-ASCII characters.
| RFC | Coverage |
|---|---|
| RFC 5322 | Message format, header fields, address syntax, threading |
| RFC 5321 | SMTP envelope derivation |
| RFC 2045 | MIME body integration via PartInterface |
| RFC 2047 | Encoded-word subjects and display names |
See src/Psl/Message/ for the full API.
How can I help you explore Laravel packages today?