Genkgo/Mail - Modern PHP 7.4+ Mail Library

Library to send e-mails over different transports and protocols (like SMTP) using immutable messages and streams. Also includes SMTP server.

Why another Mail library for PHP?

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.

Getting started

Installation

Install the library using composer. Execute the following command in your command line (in the project root).

$ composer require genkgo/mail

Message Instantiation

Use the formatted message factory to create a message

$message = (new MessageBodyCollection())
    ->withHtml('<html><body><p>Hello World</p></body></html>')
    ->withAttachment(new FileAttachment('/order1.pdf', new ContentType('application/pdf')))
    ->createMessage()
    ->withHeader(new Subject('Hello World'))
    ->withHeader(From::fromEmailAddress('from@example.com'))
    ->withHeader(To::fromSingleRecipient('to@example.com', 'name'))
    ->withHeader(Cc::fromSingleRecipient('cc@example.com', 'name'));

Send messages via SMTP

To send the message use a transport, e.g. the SMTP transport.

$transport = new SmtpTransport(
    ClientFactory::fromString('smtp://user:pass@host/')->newClient(),
    EnvelopeFactory::useExtractedHeader()
);

$transport->send($message);

Send messages via SMTP

$transport = new SmtpTransport(
    ClientFactory::fromString('smtp://user:pass@host/')->newClient(),
    EnvelopeFactory::useExtractedHeader()
);

$transport->send($message);

PHP mail function

Help wanted.

Send messages via IMAP

$transport = new ImapTransport(
    ClientFactory::fromString('imap://user:pass@host/')->newClient(),
    new MailboxName('INBOX')
);

$transport->send($message);

File

Help wanted.

Other

Help wanted.

IMAP Protocol

Help wanted.

SMTP Protocol

Help wanted.

Sign messages with DKIM

Help wanted.

Queue Message

Help wanted.