Using Mandrill / Mailgun / SendGrid as email transporter

Anyone who’s looked in to this (Kirby 3)?

I have done similar (using Postmark). If you use the Uniform plugin, you can use the Webhook action to send it. If you dont want to use that, you should be able to set it up via curl using Kirby’s remote helper.

Thanks. Yes, but I want to use Kirby core Email service, and hook it up on Madrill (or some other transactional email service), Maybe Uniform can be something to look into…

Well the easiest way is to use the built in email service and set it up as SMTP, since Mailgun supports SMTP.

But when you use SMTP I’m not able to use all the cool features that most transactional email services provide. Like scheduling and more… I want to use their API.

Well, last time i did it, I used uniform, and did it with manual curl via a custom action:

<?php

namespace Uniform\Actions;

class TransactionalAction extends Action
{
    public function perform()
    {
        try {

            // use the $remote class or setup manual curl here

        } catch (\Exception $e) {
            $this->fail($e->getMessage());
        }
    }
}

Then your uniform controller will look something like this…

<?php

use Uniform\Form;


return function ($kirby) {
   $form = new Form([
      'email_address' => [
         'rules' => ['required', 'email'],
         'message' => 'Email is required',
      ],
      'dob' => [
        'rules' => [],
      ]

   ]);

   if ($kirby->request()->is('POST')) {
     $form->transactionalAction();
  }

   return compact('form');
};

You can pick up the field data in the action with $this->form->data()["dob"] etc

As a complete example, here is what i did to send to mailchimp…

<?php

namespace Uniform\Actions;

class NewsAction extends Action
{
    public function perform()
    {
        try {

            //var_dump($this->form->data());

            // API to mailchimp ########################################################
            $list_id = 'XXX';
            $authToken = 'XXX';

            // The data to send to the API
            $originalDate = $this->form->data()["dob"];
            $newDate = date("d-m-Y", strtotime($originalDate));

            $postData = array(
                "email_address" => $this->form->data()["email_address"],
                "status" => "subscribed",
                "merge_fields" => array(
                  "DOB" => $newDate
                )
            );

            // Setup cURL
            $ch = curl_init('https://us4.api.mailchimp.com/3.0/lists/'.$list_id.'/members/');

            curl_setopt_array($ch, array(
                CURLOPT_POST => TRUE,
                CURLOPT_RETURNTRANSFER => TRUE,
                CURLOPT_HTTPHEADER => array(
                    'Authorization: Basic '.$authToken,
                    'Content-Type: application/json'
                ),
                CURLOPT_POSTFIELDS => json_encode($postData)
            ));

            // Send the request
            $response = curl_exec($ch);


        } catch (\Exception $e) {
            $this->fail($e->getMessage());
        }
    }
}

You used to be able to use the Kirby Email API with your choice of transport but it seems Kirby only uses PHPMailer now. I made a small plugin which is basically a wrapper around the Mailgun SDK, I think you’re looking at a similar solution