genkgo / mail
Library to send e-mails over different transports and protocols (like SMTP and IMAP) using immutable messages and streams. Also includes SMTP server.
Installs: 50 046
Dependents: 0
Suggesters: 0
Security: 0
Stars: 402
Watchers: 14
Forks: 21
Open Issues: 5
Requires
- php: ~8.1.0 || ~8.2.0 || ~8.3.0
- ext-iconv: *
- ext-intl: *
Requires (Dev)
- ext-openssl: *
- friendsofphp/php-cs-fixer: ^3.0
- phpstan/phpstan: ^1.8.5
- phpstan/phpstan-phpunit: ^1.1.1
- phpunit/phpunit: ^9.5.24
- predis/predis: ^1.0
- psr/log: ^1.0
Suggests
- ext-openssl: Sign your messages with DKIM
- predis/predis: Use redis to queue messages
- dev-master
- 2.12.1
- 2.12.0
- 2.11.1
- 2.11.0
- 2.10.1
- 2.10.0
- 2.9.3
- 2.9.2
- 2.9.1
- 2.9.0
- 2.8.0
- 2.7.16
- 2.7.15
- 2.7.14
- 2.7.13
- 2.7.12
- 2.7.11
- 2.7.10
- 2.7.9
- 2.7.8
- 2.7.7
- 2.7.6
- 2.7.5
- 2.7.4
- 2.7.3
- 2.7.2
- 2.7.1
- 2.7.0
- 2.6.6
- 2.6.5
- 2.6.4
- 2.6.3
- 2.6.2
- 2.6.1
- 2.6.0
- 2.5.7
- 2.5.6
- 2.5.5
- 2.5.4
- 2.5.3
- 2.5.2
- 2.5.1
- 2.5.0
- 2.4.0
- 2.3.0
- 2.2.0
- 2.1.7
- 2.1.6
- 2.1.5
- 2.1.4
- 2.1.3
- 2.1.2
- 2.1.1
- 2.1.0
- 2.0.8
- 2.0.7
- 2.0.6
- 2.0.5
- 2.0.4
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- dev-php_83
- dev-disable_first_fold
This package is auto-updated.
Last update: 2024-10-31 00:21:54 UTC
README
While analyzing what mail library to use when refactoring a code base, we discovered that the available ones are mostly legacy libraries. Some do not use namespaces and every library we encountered was merely a collection of scalar property bags than objects using encapsulation. Although we used these libs with joy in the past, they do not meet current quality standards. So, we built a new and better library according to modern programming principles.
Use this if you want to send e-mails over different transports and protocols using immutable messages and streams.
Send message quick and easy
use Genkgo\Mail; $message = (new Mail\MessageBodyCollection('<html><body><p>Hello World</p></body></html>')) ->withAttachment(new Mail\Mime\FileAttachment('/order1.pdf', new Mail\Header\ContentType('application/pdf'))) ->createMessage() ->withHeader(new Mail\Header\Subject('Hello World')) ->withHeader(Mail\Header\From::fromEmailAddress('from@example.com')) ->withHeader(Mail\Header\To::fromSingleRecipient('to@example.com', 'name')) ->withHeader(Mail\Header\Cc::fromSingleRecipient('cc@example.com', 'name')); $transport = new Mail\Transport\SmtpTransport( Mail\Protocol\Smtp\ClientFactory::fromString('smtp://user:pass@host/')->newClient(), Mail\Transport\EnvelopeFactory::useExtractedHeader() ); $transport->send($message);
Install using composer
$ composer require genkgo/mail
Features
- Use SMTP or mail() to send messages
- Use IMAPv4 to read messages from your mailbox (no extension required)
- Create replies and forward messages, including quoting of original message
- Queue messages when transport fails
- Automatically connects and reconnects after interval to SMTP server
- Automatically generate alternative text for formatted messages
- Optimal encoded headers, so no excessive (Q/B) encoded headers
- Optimal encoded multipart messages
- Only streams and connections are mutable
- Messages and actors are immutable
- Value objects protect against invalid states
- Streams make sure the library has a low memory burden
- Many objects but still easy API
- 90%+ test coverage
- Uses highest PHPStan detection level
- Only uses TLS < 1.2 if not otherwise possible
- Discourages SSL
- DKIM signed message
- Security is highly prioritized
- SMTP server for testing purposes
- Great RFC compliance
- Cast messages to valid string source
- Library has no external dependencies (but uses intl extension)
- Only supports PHP versions that are not EOL
Upcoming features
- Encrypted and signed messages
Not planned
The following features are not planned for development by the owners, but could become part of the library when initiative is taken by the community.
- POP Support
- Mailbox abstraction layer
Documentation
RFC-compliance
This library tends to be as compliant with e-mail RFCs as possible. It should be compliant with the following RFCs.
- RFC 821, Simple Mail Transfer Protocol
- RFC 1896, The text/enriched MIME Content-type
- RFC 2822, Internet Message Format
- RFC 2045, Multipurpose Internet Mail Extensions (MIME) Part One
- RFC 2046, Multipurpose Internet Mail Extensions (MIME) Part Two
- RFC 2047, Multipurpose Internet Mail Extensions (MIME) Part Three
- RFC 2048, Multipurpose Internet Mail Extensions (MIME) Part Four
- RFC 2049, Multipurpose Internet Mail Extensions (MIME) Part Five
- RFC 2392, Content-ID and Message-ID Uniform Resource Locators
- RFC 2821, Simple Mail Transfer Protocol
- RFC 3501, Internet Message Access Protocol - version 4rev1
- RFC 4954, SMTP Service Extension for Authentication
- RFC 5321, Simple Mail Transfer Protocol
- RFC 6530, Overview and Framework for Internationalized Email
Credits
This library was not able to exist without Zend/Mail and PHPMailer.