henrikbjorn/Stampie — pull request #28 by adamaveray (2014-03-14 15:33:49+00:00)
Title: Attachments

Adds support for file attachments in messages.

I've only been able to test it with Postmark, since I don't have an account with the others, but _in theory_ it works with them too – I've poured over the docs for each of them, so it should be correct for all of them.

There are unit tests for everything new I've added, and I've updated any existing tests for things I've modified. I've tried to match the coding standards already in place, let me know if I've done something differently!

**Major caveat:** Buzz isn't supported by this for mailers that use raw POST messages (SendGrid and MailGun). I couldn't figure out in the few minutes I spent looking at it how to just upload files with POST in Buzz (and [I'm not the only one](https://github.com/kriswallsmith/Buzz/issues/103)). If anyone can figure it out please let me know, but for now this just ignores the attachments and continues like before if you use Buzz. Guzzle should be fine, and Postmark and Mandrill just base64 encode attachments so they should work on Buzz still. **Summary: Buzz + SendGrid/MailGun = no attachments**

_(There was also an issue preventing the Postmark tests being run – they were being manually included into a different file, so weren't being run. I've fixed that, but they weren't passing, so they pass now too!)_

cc: #2

-----

Postmark example:

~~~php
// Usual setup
$adapter = new \Stampie\Adapter\Guzzle(new \Guzzle\Service\Client());
$mailer = new \Stampie\Mailer\Postmark($adapter, 'apikey');
$to = new \Stampie\Identity('test@example.com');

$message = new CustomMessage($to); // Implements \Stampie\Message\AttachmentsInterface
$message->setAttachments(array(
new \Stampie\Attachment('path/to/file.jpg', 'attachment.jpg', 'image/jpg'), // Normal attachment
new \Stampie\Attachment('path/to/other.jpg', 'other.jpg', 'image/jpg', 'cid:12345@example.com'), // Can be embedded using
));
$mailer->send($message);
~~~