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

Get it here.

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.

5 Responses to “Postmark library for CodeIgniter”

  1. Hristo Deshev  on January 25th, 2010

    Hey, János,

    Mind posting the code to github? Or letting me post it? I’m sure some PHP masters would start some crazy forking :-)

    Hristo

  2. Janos  on January 25th, 2010

    Post it please as I have no experience with Git and I don’t want to mess up. :)

  3. Hristo Deshev  on January 25th, 2010

    Done. It is available at:

    http://github.com/hdeshev/postmark-codeigniter

    Thanks for contributing this code. Much appreciated.

    Hristo

  4. Janos  on January 25th, 2010

    I updated the post with the github link.

  5. jeremy  on February 23rd, 2010

    nice work. i’ve been watching postmark as it develops, and i’m looking forward to using it on projects after it launches.

    your library will be a big help with that.


Leave a Reply