2017 © Pedro Peláez
 

library mail

The Hoa\Mail library.

image

hoa/mail

The Hoa\Mail library.

  • Tuesday, March 6, 2018
  • by Hoa
  • Repository
  • 12 Watchers
  • 20 Stars
  • 1,607 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 10 Forks
  • 4 Open issues
  • 14 Versions
  • 12 % Grown

The README.md

Hoa , (*1)


Build status Code coverage Packagist License , (*2)

Hoa is a modular, extensible and structured set of PHP libraries.
Moreover, Hoa aims at being a bridge between industrial and research worlds. , (*3)

Hoa\Mail

Help on IRC Help on Gitter Documentation Board, (*4)

This library allows to compose and send rich emails (textual contents, HTML documents, alternative contents, attachments etc., this is very extensible). Email can be sent with sendmail or SMTP. The SMTP layer supports TLS and PLAIN, LOGIN and CRAM-MD5 authentications., (*5)

In a near future, this library will also allow to receive and parse emails., (*6)

Learn more., (*7)

Installation

With Composer, to include this library into your dependencies, you need to require hoa/mail:, (*8)

$ composer require hoa/mail '~0.0'

For more installation procedures, please read the Source page., (*9)

Testing

Before running the mail suites, the development dependencies must be installed:, (*10)

$ composer install

Then, to run all the test suites:, (*11)

$ vendor/bin/hoa test:run

For more information, please read the contributor guide., (*12)

Quick usage

We propose a quick overview to send a very simple email with only one content, and then, a more complex email with an alternative content and an attachment., (*13)

Simple email

Before all, just like any messaging softwares, we have to setup the transport. We will send our email by using SMTP as the default transport. We will specify a socket to the SMTP server, a login and a password:, (*14)

Hoa\Mail\Message::setDefaultTransport(
    new Hoa\Mail\Transport\Smtp(
        new Hoa\Socket\Client('tcp://mail.domain.tld:587'),
        'gordon_freeman',
        '*********'
    )
);

Then, we will get an instance of a message and set all the headers, such as From, To and Subject, we will add a textual content and we will send it:, (*15)

$message            = new Hoa\Mail\Message();
$message['From']    = 'Gordon Freeman <gordon@freeman.hf>';
$message['To']      = 'Alyx Vance <alyx@vance.hf>';
$message['Subject'] = 'Hoa is awesome!';

$message->addContent(
    new Hoa\Mail\Content\Text('Check this out: http://hoa-project.net/!')
);

$message->send();

Notice that we can use any view or template library to produce the content of the mail!, (*16)

Rich email

Now, instead of having only one textual content, we will have an alternative content: either textual or HTML., (*17)

$message->addContent(
    // We have either…
    new Hoa\Mail\Content\Alternative([
        // … a text content
        new Hoa\Mail\Content\Text(
            'Check this out: http://hoa-project.net/!'
        ),
        // … or an HTML content.
        new Hoa\Mail\Content\Html(
            '<a href="http://hoa-project.net/">Check this ' .
            '<strong>out</strong>!</a>'
        )
    ])
);

Then, to add an attachment, we will add a new kind of content. The attachment is an image that will be named Foobar.jpg. Thus:, (*18)

$message->addContent(
    new Hoa\Mail\Content\Attachment(
        new Hoa\File\Read('Attachment.jpg'),
        'Foobar.jpg'
    )
);

And finally, we send the email:, (*19)

$message->send();

Complex email

Now imagine we do not want the image to be only attached but appear in the HTML content. These contents are related. Here is how to construct the email (with more variables to clarify):, (*20)

// The image.
$attachment = new Hoa\Mail\Content\Attachment(
    new Hoa\File\Read('Attachment.jpg'),
    'Foobar.jpg'
);
// The text content.
$text = new Hoa\Mail\Content\Text('Check this out: http://hoa-project.net/!');
// The HTML content.
$html = new Hoa\Mail\Content\Html(
    '<img src="' .
    // The HTML image URL is the attachment ID URL.
    $attachment->getIdUrl() .
    '" />'
);

$message->addContent(
    // Alternative contents and attachment are related.
    new Hoa\Mail\Content\Related([
        // We still have 2 alternative contents: text or HTML.
        new Hoa\Mail\Content\Alternative([$text, $html]),
        $attachment
    ])
);

Documentation

The hack book of Hoa\Mail contains detailed information about how to use this library and how it works., (*21)

To generate the documentation locally, execute the following commands:, (*22)

$ composer require --dev hoa/devtools
$ vendor/bin/hoa devtools:documentation --open

More documentation can be found on the project's website: hoa-project.net., (*23)

Getting help

There are mainly two ways to get help:, (*24)

Contribution

Do you want to contribute? Thanks! A detailed contributor guide explains everything you need to know., (*25)

License

Hoa is under the New BSD License (BSD-3-Clause). Please, see LICENSE for details., (*26)

The Versions

06/03 2018

dev-master

9999999-dev https://hoa-project.net/

The Hoa\Mail library.

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

mail library imap rfc4648 smtp sendmail rfc2111 rfc2045 rfc2047 rfc2104 rfc2487 rfc3207 rfc2821

13/01 2017

0.17.01.13

0.17.01.13 https://hoa-project.net/

The Hoa\Mail library.

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

mail library imap rfc4648 smtp sendmail rfc2111 rfc2045 rfc2047 rfc2104 rfc2487 rfc3207 rfc2821

24/05 2016

0.16.05.24

0.16.05.24 http://hoa-project.net/

The Hoa\Mail library.

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

mail library imap rfc4648 smtp sendmail rfc2111 rfc2045 rfc2047 rfc2104 rfc2487 rfc3207 rfc2821

11/01 2016

0.16.01.11

0.16.01.11 http://hoa-project.net/

The Hoa\Mail library.

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

mail library imap rfc4648 smtp sendmail rfc2111 rfc2045 rfc2047 rfc2104 rfc2487 rfc3207 rfc2821

29/10 2015

0.15.10.29

0.15.10.29 http://hoa-project.net/

The Hoa\Mail library.

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

mail library imap rfc4648 smtp sendmail rfc2111 rfc2045 rfc2047 rfc2104 rfc2487 rfc3207 rfc2821

28/08 2015

0.15.08.28

0.15.08.28 http://hoa-project.net/

The Hoa\Mail library.

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

mail library imap rfc4648 smtp sendmail rfc2111 rfc2045 rfc2047 rfc2104 rfc2487 rfc3207 rfc2821

17/08 2015

0.15.08.17

0.15.08.17 http://hoa-project.net/

The Hoa\Mail library.

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

mail library imap rfc4648 smtp sendmail rfc2111 rfc2045 rfc2047 rfc2104 rfc2487 rfc3207

03/06 2015

0.15.06.03

0.15.06.03 http://hoa-project.net/

The Hoa\Mail library.

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

mail library imap rfc4648 smtp sendmail rfc2111 rfc2045 rfc2047 rfc2104

20/05 2015

0.15.05.20

0.15.05.20 http://hoa-project.net/

The Hoa\Mail library.

  Sources   Download

BSD-3-Clause

The Requires

 

mail library imap smtp pop3 sendmail

23/02 2015

0.15.02.23

0.15.02.23 http://hoa-project.net/

The Hoa\Mail library.

  Sources   Download

BSD-3-Clause

The Requires

 

mail library imap smtp pop3 sendmail

09/12 2014

0.14.12.10

0.14.12.10 http://hoa-project.net/

The Hoa\Mail library.

  Sources   Download

BSD-3-Clause

The Requires

 

mail library imap smtp pop3 sendmail

23/09 2014

0.14.09.23

0.14.09.23 http://hoa-project.net/

The Hoa\Mail library.

  Sources   Download

BSD-3-Clause

The Requires

 

mail library imap smtp pop3 sendmail

17/09 2014

0.14.09.17

0.14.09.17 http://hoa-project.net/

The Hoa\Mail library.

  Sources   Download

BSD-3-Clause

The Requires

 

mail library imap smtp pop3 sendmail

16/09 2014

0.14.09.16

0.14.09.16 http://hoa-project.net/

The Hoa\Mail library.

  Sources   Download

BSD-3-Clause

The Requires

 

mail library imap smtp pop3 sendmail