Postmark library for CodeIgniter
Friday afternoon I received an invite to try out the beta version of Postmark, a transactional e-mail delivery service from Wildbit, the guys and gals who made Beanstalk and Newsberry. What are transactional e-mails, you might ask? The answer is: e-mails generated by a web application after an user action such as registration, requesting a password reminder, receiving a reply to a comment, etc. The problem me and many developers faced is that sometimes the client’s servers are blacklisted and these e-mails land in the users’ spam folder. This is where Postmark comes to the rescue, hopefully – instead of using the built in mail function of your web development language of choice you issue a call to Postmark which sends out the e-mail from their “well regarded” servers so that hopefully they land in the user’s inbox.
To give something back, I’ve put together a CodeIgniter library for this service. This grants easy integration of Postmark with your CodeIgniter web app: you upload two files, fill in your API key then include the library where needed and send mails away.
Download & credits
You can contribute to this code here.
Based on Markus Hedlund’s Postmark class for PHP.
Installation
Upload the contents of the cipostmark folder from the archive to the root of your CodeIginiter install directory (on Mac be sure to merge with the existing folders). Basically Postmark.php (with capital P) needs to sit in /system/application/libraries/ and postmark.php needs to be uploaded to /system/application/config/ – Before or after uploading edit the configuration file (postmark.php) and fill in your API key.
Usage guide
Now you can use the library in your web app:
$this->load->library('postmark');
$this->postmark->from('from@example.com', 'From Name');
$this->postmark->to('to@example.com', 'To Name);
$this->postmark->subject('Example subject');
$this->postmark->messagePlain('Testing...');
$this->postmark->messageHtml('<html><strong>Testing...</strong></html>');
$this->postmark->send();
… or you can specify all the parameters in the send() function like this:
$this->load->library('postmark');
$this->postmark->send('from@example.com', 'From Name', 'to@example.com', 'To Name', 'Example Subject', 'Testing...', '<html><strong>Testing...</strong></html>');
If something goes wrong the library and the Postmark service outputs quite user friendly error messages.
Hopefully this will come in handy for some of you.


