Every developer in their career has been asked to build a transactional email at least once. It usually starts with a simple request like:
Please could you send a simple email when a contact form is submitted, something very simple, nothing special.
A few minutes search on Google or Stackoverflow and “snap”, we find perfectly what we need, the php mail function just does what we need right? The description says “Sends an email” what can go wrong?! Well LOTS.
So we have then starter to create our own implementation of a safe mail sender, we start to create templates, we improve our knowledge of crazy workaround needed for HTML formatting in emails and of course they end in the spam, no matter how clear the content is and our previous excitement just turned into our biggest nightmare.
Don’t reinvent the wheel
Unfortunately the reason why I am writing this post, is because I have been there. I have gone through all the nightmares explained above, and trust my words when I say the word nightmares.
There are company that with great product and the right marketing campaigns, have been able to became the leading providers in the industry (eg. WordPress, Mailchimp, etc..).
Today I am going to share with you what I found to be one of the best provider in transactional email that maybe and hopefully be part of that “right marketing campaigns” that can helps them.
Mail sent and delivered.. hassle free!
Over a year ago, I was ask to implement an easy to use way to create Email templates, that would be reliable, easy to change (code free) and with added analytics. (the conversation started with the sentence shared above.. it was supposed to be an easy job they said 🙂 ).
Postmark was my final choice and I have no regret as it has not only delivered all it was required for me, but it also provides fantastic customer service ( fast and reliable) with affordable plans (They provide initial 25000 email free, plus extra free token that are provided as the service get used more, that is more than enough for a small/medium company).
See to believe
I am going to post below a small example taken directly form my project by creating a very simple email template and show the code required to deliver it. There will be no explanation on how to create an account, and how to fetch the unique key, as the documentation of the website is just great on that.
Step 1 – Create the template
Login into your account and then click on the “Add a new template” button situated in the template section.
Postmark provides you with a list of templates. Each of the templates provides a very details post with all the information required to create your own version of the template with tons of tips around email requirements, but it also give you the ability to use the open source templates provided by them, or of course start from a blank canvas.
For the purpose of this example we are going to use the existing Welcome template.
Step 2 – Modify the template
The Web App provides a very easy to use IDE, everything is within reach, and the template provides you with all the basic structure and example needed.
This editor provides you with a Template name, Subject line, HTML editor, live preview, a variables object, ability to fill the email with test data to see how the email layout will react, a “Send Test” button to see what an email really look like and to finish off, an “API snippets” .
The snippets provide you with everything you need, all the code has been dynamically filled with your account information, the template id and also all the variables.
The code is provided in 5 different languages curl, Ruby, C#, PHP and Node.js.
If this snippets is not enough, you can be assured to be supported by a great customer service ( I had a lovely personal experience and I deals with 3 different people).
Step 3 – The code
After creating your HTML template and setting the right variables and small details, there is nothing else left than copy this snippets into the portion of your code than handles the email and replace the variable with actual values.
// Create Client $client = new PostmarkClient("000000000000-0000-00000000000"); // Make a request $sendResult = $client->sendEmailWithTemplate( "email@example.com", "firstname.lastname@example.org", 1526526, [ "name" => $_POST["name"], "username" => $_POST["username"] ]); ?>
That is it, no more code required.
I am usually reluctant to use external tools or API as it makes your product fragile, but there are some cases where the risk is worth while, and this is one of them.
The tons of hours I saved after introducing Postmark and clear way to use it has made this a must have for every of my project small or big.
In this post I have really just touched the surface, as the Web App offers many more features and benefits ( for example low possibility of spam because they make sure no one uses the APP for spams emails and they do any effort to keep the servers clears), and hope after trying it out, you will share my same view.
Postmark – https://postmarkapp.com/
image from postmarkapp website