quartzy/php-email

This package is abandoned and no longer maintained. No replacement package was suggested.

A domain model for describing emails that is indifferent towards sending methods.

0.6.0 2018-12-19 22:37 UTC

This package is auto-updated.

Last update: 2022-08-31 00:08:51 UTC


README

Latest Version on Packagist Total Downloads Software License Build Status Coverage Status Style Status Scrutinizer Code Quality

This is a domain-driven library for defining emails in PHP.

Php Email brings three major benefits over other similar libraries:

  1. Focusing on new versions of PHP. By using the newer versions of PHP (5.6+) we can leverage great features such as splat parameters and better type hinting.
  2. Focusing on only the email, instead of transmission. In a domain-driven world, emails can and should exist separately from the delivery mechanism. By separating these concerns, this library decreases the size and complexity of the domain, while giving developers greater flexibility in how they use the library.
  3. Flexible content definitions. Emails have gone from a simple text string to highly stylized HTML to now just being templates stored in third-party services. Existing libraries do not provide enough flexibility to support everything developers need. Php Email attempts to correct this by creating guidelines for possible email content, but also allowing developers to define what they need.

Install

With Composer

composer require quartzy/php-email

Usage

Building an email with HTML and text content would look like:

<?php

use PhpEmail\Attachment\FileAttachment;
use PhpEmail\EmailBuilder;
use PhpEmail\Content\SimpleContent;

$email = EmailBuilder::email()
    ->withSubject('Welcome!')
    ->withContent(SimpleContent::text('Start your free trial now!!!'))
    ->from('me@test.com')
    ->to('you@yourbusiness.com')
    ->cc('cc@test.com')
    ->bcc('bcc@test.com')
    ->replyTo('reply.to@test.com')
    ->attach(new FileAttachment('/path/to/my/file.txt'))
    ->build();

Sending a templated email:

<?php

use PhpEmail\EmailBuilder;
use PhpEmail\Content\TemplatedContent;

$content = new TemplatedContent('my_templates_id', ['firstName' => 'Billy']);

$email = EmailBuilder::email()
    ->withSubject('Welcome!')
    ->withContent($content)
    ->from('me@test.com')
    ->to('you@yourbusiness.com')
    ->build();

Change log

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING and CONDUCT for details.

Security

If you discover any security related issues, please email opensource@quartzy.com instead of using the issue tracker.

Credits

License

The Apache License, v2.0. Please see License File for more information.