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.
https://mail.readthedocs.io/
Other
402 stars 21 forks source link
e-mail imap immutable mail mime php queue redis smtp value-object

Genkgo/Mail - Modern PHP Mail Library

Latest Version workflow code check

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

Upcoming features

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.

Documentation

RFC-compliance

This library tends to be as compliant with e-mail RFCs as possible. It should be compliant with the following RFCs.

Credits

This library was not able to exist without Zend/Mail and PHPMailer.