Symfony2 bundle for Postmark API
Using Composer Add PostmarkBundle in your composer.json:
{
"require": {
"mlpz/postmark-bundle": "*"
}
}
$ php composer.phar update mlpz/postmark-bundle
Using Submodule
git submodule add https://github.com/miguel250/PostmarkBundle.git vendor/bundles/MZ/PostmarkBundle
git submodule add https://github.com/kriswallsmith/Buzz.git vendor/buzz
Add the MZ namespace to autoloader You can skip this when using Composer
<?php
// app/autoload.php
$loader->registerNamespaces(array(
// ...
'MZ' => __DIR__.'/../vendor/bundles',
'Buzz' => __DIR__.'/../vendor/buzz/lib',
));
Add PostmarkBundle to your application kernel
<?php
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new MZ\PostmarkBundle\MZPostmarkBundle(),
);
}
Enable Postmark in config.yml
mz_postmark:
api_key: API KEY
from_email: [email protected]
from_name: My App, Inc
use_ssl: true
timeout: 5
Message Service
<?php
$message = $this->get('postmark.message');
$message->addTo('[email protected]', 'Test Test');
$message->setSubject('subject');
$message->setHTMLMessage('<b>email body</b>');
$message->addAttachment(new Symfony\Component\HttpFoundation\File\File(__FILE__));
$message->send();
$message->addTo('[email protected]', 'Test2 Test');
$message->setSubject('subject2');
$message->setHTMLMessage('<b>email body</b>');
$message->addAttachment(new Symfony\Component\HttpFoundation\File\File(__FILE__), 'usethisfilename.php', 'text/plain');
$message->send();
?>
Sending in batch
<?php
$message = $this->get('postmark.message');
$message->addTo('[email protected]', 'Test Test');
$message->setSubject('subject');
$message->setHTMLMessage('<b>email body</b>');
$message->queue(); // Queue the message instead of sending it directly
$message->addTo('[email protected]', 'Test2 Test');
$message->setSubject('subject2');
$message->setHTMLMessage('<b>email body</b>');
$message->send(); // Send both messages
?>