hyperdigital/raw-email

Raw email library

1.0.1 2015-06-04 15:49 UTC

This package is auto-updated.

Last update: 2024-11-18 07:10:08 UTC


README

This library simplifies work with emails in PHP. The main class – RawEmail.php offers building a raw email. The raw email supports:

  • Attachments
  • Multiple recipients
  • Both HTML and Plain text versions

Install via composer

composer require hyperdigital/raw-email

Use

<?php

use Hyperdigital\RawEmail\RawEmail;

$html = "<h1>HTML version</h1>";
$rawEmail = new RawEmail("no-reply@hyperdigital.de", "no-reply@hyperdigital.de");
$rawData = $rawEmail->build(array('developer@hyperdigital.de'), 'Some subject', 'Plain text version', $html);

// Send the email data

Use with Amazon SES (example using ^2.8)

  • Install aws/aws-sdk-php via composer
composer require aws/aws-sdk-php ^2.8
<?php

use Aws\Common\Aws;
use Hyperdigital\RawEmail\RawEmail;

$html = "<h1>HTML version</h1>";
$rawEmail = new RawEmail("no-reply@hyperdigital.de", "no-reply@hyperdigital.de");
$rawData = $rawEmail->build(array('developer@hyperdigital.de'), 'Some subject', 'Plain text version', $html);

$aws = Aws::factory($credentials);
$ses = $aws->get('Ses');

$ses->sendRawEmail(array(
    'RawMessage' => array(
        'Data' => base64_encode($rawData),
        ),
    )
);

Advanced

If you need some additional functionality, feel free to inspect how RawEmail.php class works and use the component classes to create your customized emails.