---
title: "Gridpane: Setting Up Email Delivery"
date: 2024-12-31T15:43:09Z
modified: 2026-09-22T19:51:44Z
permalink: "https://techarticles.co.uk/gridpane-setting-up-email-delivery/"
type: post
status: publish
excerpt: ""
wpid: 4017
categories:
  - Coding
  - GridPane
  - Hosting
  - Wordpress
featured_image: "https://techarticles.co.uk/wp-content/uploads/2024/12/Gridpane-Postmark.png"
featured_image_alt: TechArticles guide on deploying Gridpane and Postmark during site setup, featuring a laptop and plugins interface.
timestamp: 2026-09-22T19:51:44Z
tags:
  - Coding
  - GridPane
  - Hosting
  - Wordpress
---

**A bit of Background**:

I am a big fan of [GridPane](https://ta0.uk/gridpane). I don’t currently offer any hosting and only really host a few sites of my own; I picked up one of their Developer LTDs a few years ago, the biggest WP purchase I’ve ever made, and have been getting my value out of it ever since. My sites are not uptime critical, but I am one of those people who want things to work and want the control I need and/or want at the time, and I still believe that GridPane now offers that.

Now, In terms of normal GridPane users, I am probably an anomaly. I don’t offer web hosting as a service but have used many of their feature set, Git, Canary, bundles, sever clone, site clone and even their API… I am not a regular user; I like to automate and deeply understand what I am using, and with GridPane, I feel I have a good understanding because of their bring-your-own-server model. I currently have about 10 in my account; only two are used, and the rest are just idling, ready for me to decide to use them.

Now, I am not a lucrative customer of GridPane. I don’t need flashy additional options, and I am pretty self-sufficient; with a great API, the GUI probably would only be used to access rarely used features, such as getting the user details for SFTP, but I knew reading about GridPane the stack and there dedication to GOOD hosting it was what I wanted.

Now, I recently commented on the Admin Bar Community about if anyone else finds GridPane’s API a bit frustrating; it has really low rate limits, and the methodology isn’t precisely slick; it requires far too many probes to get and do what you need, Patrick did comment on this and say they are looking to relaunch there API and has offered to show me there plans which I will certainly do, if I can help shape the way the API works this would be really good and as an avid fan of automation this to me seems like a no brainer (Plus I can see a nice tutorial series on automating with GridPane for automatic account creations, adding to Main WP, suspending and deleting on non-payment etc.)

**The Problem:**

On this thread, another user asked about Postmark integration within GridPane, and it got me thinking about something else Patrick said in that thread: “Most people in the WP ecosystem don’t really have the chops to build something from the ground up that even integrates a handful of simple API requests……….What it is that people really want is basically just a white label version of Kinsta/similar that they can slap their own logo on and call their own.”

See GridPane like [InstaWP](https://ta0.uk/InstaWP), another service I utilise at least until the API works a little better. Has no email delivery service, so you need to integrate with your provider to do this. You currently have two choices: set up your own SMTP / API within your WordPress site or utilise the GridPane API integration with Sendgrid.

![](https://techarticles.co.uk/wp-content/uploads/2024/12/Gridpane-Sendgrid.png)

It turns out I had already solved this (well, practically). Previously, I’ve used the useful [FluentSMTP ](https://wordpress.org/plugins/fluent-smtp/)for SMTP delivery by a provider of my choice, and it works flawlessly in most cases except for two things.

1\) it doesn’t work out of the box, so for tutorials, this means setting up SMTP delivery before I can use a site. In some cases, that can only last a few minutes; this just adds another unnecessary step for that work

2\) I recently moved to a server provider that blocks standard SMTP ports for one of my actual live servers not by choice,e but it was what had to happen; this left me unable to utilise my usual transactional email delivery service

I also recently acquired an [emailit](https://emailit.com/) account that offers API email delivery on a lifetime deal and also has very generous purchase credits that don’t expire. This let me look for other alternative methods. I hit upon the only reliable method, in my opinion,n beyond integration at the panel level, and this is an [MU Plugin](https://developer.wordpress.org/advanced-administration/plugins/mu-plugins/). It can’t be easily removed by mistake. It is there, and it loads as soon as the site does, so it is always there, set and waiting.

To fellow GridPane users, this isn’t new to you. We all have one already installed that allows the little automatically login to the server button to work within GridPane, and there are some good examples on the [GridPane-Dev github](https://github.com/GridPane-Dev/gridpane-wordpress-template-all-plugins/tree/main/wp-content/mu-plugins)

![WP CLI Login Command Server plugin details with version 1.5 by Evan Mattson.](https://techarticles.co.uk/wp-content/uploads/2024/12/gridpane-default-mu.png)

So, with my mind set up, I wrote an API interface which allows me to have an MU plugin that delivers via email and designed a delivery method for delivering the “payload” on-site setup.

In my personal opinion, it’s pretty elegant and simple.

1\. As per the usual GridPane bundle emailit-deploy.zip gets added and activated from my personal repo

2\. Emailit-deploy has only one job: it creates a mu-plugin file in the mu-directory, and then once it has done this, it deactivates and deletes itself much the same as my fork and improvement of [WP-Tasks-After-Install](https://github.com/stingray82/WP-Tasks-After-Install) does after it has done its modifications

It works great, and my sites with it installed in testing have had emails work perfectly to from the beginning. It works so well because emailit authorises sending domains, i.e. \*@domain.com, and this means using a generic domain, I can have all emails delivered by that domain with the site title as the sender.

I have also added the ability to replace the hardcoded values within the mu-plugin with custom ones for each domain by using override values in WPcodeBox or functions.php, including a single one that allows me to turn off this MU plugin full stop if I want to

So, my next challenge was to see if I could get this to work with Postmark. After reviewing postmarks API for PHP and curl and comparing them to what I already had for emailit, I concluded that it was reasonably easy for me to do this based on the code I already had.

```
<span class="line"><span style="color: #F97583"><?</span><span style="color: #79B8FF">php</span></span>
<span class="line"></span>
<span class="line"><span style="color: #6A737D">// Import the Postmark Client Class:</span></span>
<span class="line"><span style="color: #F97583">require_once</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">'./vendor/autoload.php'</span><span style="color: #E1E4E8">);</span></span>
<span class="line"><span style="color: #F97583">use</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">Postmark\PostmarkClient</span><span style="color: #E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #E1E4E8">$client </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">new</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">PostmarkClient</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">""</span><span style="color: #E1E4E8">);</span></span>
<span class="line"><span style="color: #E1E4E8">$fromEmail </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">"hello@techarticles.co.uk"</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">$toEmail </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">"hello@techarticles.co.uk"</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">$subject </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">"Hello from Postmark"</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">$htmlBody </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">"<strong>Hello</strong> dear Postmark user."</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">$textBody </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">"Hello dear Postmark user."</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">$tag </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">"example-email-tag"</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">$trackOpens </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">true</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">$trackLinks </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">"None"</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">$messageStream </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">"website-notifications"</span><span style="color: #E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #6A737D">// Send an email:</span></span>
<span class="line"><span style="color: #E1E4E8">$sendResult </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> $client</span><span style="color: #F97583">-></span><span style="color: #B392F0">sendEmail</span><span style="color: #E1E4E8">(</span></span>
<span class="line"><span style="color: #E1E4E8">  $fromEmail,</span></span>
<span class="line"><span style="color: #E1E4E8">  $toEmail,</span></span>
<span class="line"><span style="color: #E1E4E8">  $subject,</span></span>
<span class="line"><span style="color: #E1E4E8">  $htmlBody,</span></span>
<span class="line"><span style="color: #E1E4E8">  $textBody,</span></span>
<span class="line"><span style="color: #E1E4E8">  $tag,</span></span>
<span class="line"><span style="color: #E1E4E8">  $trackOpens,</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #79B8FF">NULL</span><span style="color: #E1E4E8">, </span><span style="color: #6A737D">// Reply To</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #79B8FF">NULL</span><span style="color: #E1E4E8">, </span><span style="color: #6A737D">// CC</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #79B8FF">NULL</span><span style="color: #E1E4E8">, </span><span style="color: #6A737D">// BCC</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #79B8FF">NULL</span><span style="color: #E1E4E8">, </span><span style="color: #6A737D">// Header array</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #79B8FF">NULL</span><span style="color: #E1E4E8">, </span><span style="color: #6A737D">// Attachment array</span></span>
<span class="line"><span style="color: #E1E4E8">  $trackLinks,</span></span>
<span class="line"><span style="color: #E1E4E8">  </span><span style="color: #79B8FF">NULL</span><span style="color: #E1E4E8">, </span><span style="color: #6A737D">// Metadata array</span></span>
<span class="line"><span style="color: #E1E4E8">  $messageStream</span></span>
<span class="line"><span style="color: #E1E4E8">);</span></span>
<span class="line"></span>
<span class="line"><span style="color: #F97583">?></span></span>
```PHP

So, I signed up for a test account and had a working solution before Postmark even approved my account; I had to add my “domain” to Postmark. It is hard coded to use one of my approved domains, but it works right out of the box as intended emails are delivered to and from my email account.

```
<span class="line"><span style="color: #F97583"><?</span><span style="color: #79B8FF">php</span></span>
<span class="line"><span style="color: #6A737D">/**</span></span>
<span class="line"><span style="color: #6A737D"> * Plugin Name:       Gridpane - Postmark API Interface</span></span>
<span class="line"><span style="color: #6A737D"> * Plugin URI:        https://reallyusefulplugins.com</span></span>
<span class="line"><span style="color: #6A737D"> * Description:       Sends emails through the Postmark API Interface</span></span>
<span class="line"><span style="color: #6A737D"> * Version:           1.0</span></span>
<span class="line"><span style="color: #6A737D"> * Author:            Reallyusefulplugins.com</span></span>
<span class="line"><span style="color: #6A737D"> * Author URI:        https://reallyusefulplugins.com</span></span>
<span class="line"><span style="color: #6A737D"> * License:           GPL-2.0+</span></span>
<span class="line"><span style="color: #6A737D"> * License URI:       http://www.gnu.org/licenses/gpl-2.0.txt</span></span>
<span class="line"><span style="color: #6A737D"> * Text Domain:       postmark-api-interface</span></span>
<span class="line"><span style="color: #6A737D"> *</span></span>
<span class="line"><span style="color: #6A737D"> * To override the default settings, define the following constants in wp-config.php or a custom snippet:</span></span>
<span class="line"><span style="color: #6A737D"> *</span></span>
<span class="line"><span style="color: #6A737D"> * // Override the Server Token</span></span>
<span class="line"><span style="color: #6A737D"> * define('POSTMARK_SERVER_TOKEN', 'your-override-server-token');</span></span>
<span class="line"><span style="color: #6A737D"> *</span></span>
<span class="line"><span style="color: #6A737D"> * // Override the From Email</span></span>
<span class="line"><span style="color: #6A737D"> * define('POSTMARK_FROM_EMAIL', 'override</span><span style="color: #F97583">@example</span><span style="color: #6A737D">.com');</span></span>
<span class="line"><span style="color: #6A737D"> *</span></span>
<span class="line"><span style="color: #6A737D"> * // Override the Message Stream</span></span>
<span class="line"><span style="color: #6A737D"> * define('POSTMARK_MESSAGE_STREAM', 'override-stream');</span></span>
<span class="line"><span style="color: #6A737D"> */</span></span>
<span class="line"></span>
<span class="line"><span style="color: #6A737D">// Hardcoded defaults</span></span>
<span class="line"><span style="color: #79B8FF">define</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">'POSTMARK_DEFAULT_SERVER_TOKEN'</span><span style="color: #E1E4E8">, </span><span style="color: #9ECBFF">''</span><span style="color: #E1E4E8">); </span><span style="color: #6A737D">//replace</span></span>
<span class="line"><span style="color: #79B8FF">define</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">'POSTMARK_DEFAULT_FROM_EMAIL'</span><span style="color: #E1E4E8">, </span><span style="color: #9ECBFF">''</span><span style="color: #E1E4E8">); </span><span style="color: #6A737D">//replace</span></span>
<span class="line"><span style="color: #79B8FF">define</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">'POSTMARK_DEFAULT_MESSAGE_STREAM'</span><span style="color: #E1E4E8">, </span><span style="color: #9ECBFF">''</span><span style="color: #E1E4E8">); </span><span style="color: #6A737D">//replace</span></span>
<span class="line"></span>
<span class="line"><span style="color: #6A737D">/**</span></span>
<span class="line"><span style="color: #6A737D"> * Intercept and send emails via the Postmark API.</span></span>
<span class="line"><span style="color: #6A737D"> */</span></span>
<span class="line"><span style="color: #F97583">function</span><span style="color: #E1E4E8"> </span><span style="color: #B392F0">rup_postmark_intercept_and_send_email_via_api</span><span style="color: #E1E4E8">($phpmailer) {</span></span>
<span class="line"><span style="color: #E1E4E8">     </span><span style="color: #6A737D">// Check if the override variable is set and true; if so, do nothing</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">if</span><span style="color: #E1E4E8"> (</span><span style="color: #79B8FF">defined</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">'td_postmark_email_override'</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">&&</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">td_email_override</span><span style="color: #E1E4E8">) {</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #79B8FF">error_log</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">'Postmark API Override active; plugin execution skipped.'</span><span style="color: #E1E4E8">);</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">return</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">    }</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #6A737D">// Get the Server Token, allowing override via a constant or snippet</span></span>
<span class="line"><span style="color: #E1E4E8">    $server_token </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">defined</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">'POSTMARK_SERVER_TOKEN'</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">?</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">POSTMARK_SERVER_TOKEN</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">:</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">POSTMARK_DEFAULT_SERVER_TOKEN</span><span style="color: #E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #6A737D">// Get the From Email, allowing override via constants or snippets</span></span>
<span class="line"><span style="color: #E1E4E8">    $from_email </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">defined</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">'POSTMARK_FROM_EMAIL'</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">?</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">POSTMARK_FROM_EMAIL</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">:</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">POSTMARK_DEFAULT_FROM_EMAIL</span><span style="color: #E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #6A737D">// Get the Message Stream, allowing override via constants or snippets</span></span>
<span class="line"><span style="color: #E1E4E8">    $message_stream </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">defined</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">'POSTMARK_MESSAGE_STREAM'</span><span style="color: #E1E4E8">) </span><span style="color: #F97583">?</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">POSTMARK_MESSAGE_STREAM</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">:</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">POSTMARK_DEFAULT_MESSAGE_STREAM</span><span style="color: #E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #6A737D">// Extract email details from PHPMailer</span></span>
<span class="line"><span style="color: #E1E4E8">    $to_addresses </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> $phpmailer</span><span style="color: #F97583">-></span><span style="color: #B392F0">getToAddresses</span><span style="color: #E1E4E8">();</span></span>
<span class="line"><span style="color: #E1E4E8">    $subject </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> $phpmailer</span><span style="color: #F97583">-></span><span style="color: #E1E4E8">Subject </span><span style="color: #F97583">?:</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">'No Subject'</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">    $html_body </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> $phpmailer</span><span style="color: #F97583">-></span><span style="color: #E1E4E8">Body </span><span style="color: #F97583">?:</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">'<strong>No content provided.</strong>'</span><span style="color: #E1E4E8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #6A737D">// Validate 'to' addresses</span></span>
<span class="line"><span style="color: #E1E4E8">    $to </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> [];</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">foreach</span><span style="color: #E1E4E8"> ($to_addresses </span><span style="color: #F97583">as</span><span style="color: #E1E4E8"> $address) {</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">if</span><span style="color: #E1E4E8"> (</span><span style="color: #79B8FF">filter_var</span><span style="color: #E1E4E8">($address[</span><span style="color: #79B8FF">0</span><span style="color: #E1E4E8">], </span><span style="color: #79B8FF">FILTER_VALIDATE_EMAIL</span><span style="color: #E1E4E8">)) {</span></span>
<span class="line"><span style="color: #E1E4E8">            $to[] </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> $address[</span><span style="color: #79B8FF">0</span><span style="color: #E1E4E8">]; </span><span style="color: #6A737D">// Extract email address</span></span>
<span class="line"><span style="color: #E1E4E8">        }</span></span>
<span class="line"><span style="color: #E1E4E8">    }</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">if</span><span style="color: #E1E4E8"> (</span><span style="color: #79B8FF">empty</span><span style="color: #E1E4E8">($to)) {</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #79B8FF">error_log</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">'Postmark API Error: No valid recipients'</span><span style="color: #E1E4E8">);</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #F97583">return</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">    }</span></span>
<span class="line"><span style="color: #E1E4E8">    $to </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">implode</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">','</span><span style="color: #E1E4E8">, $to);</span></span>
<span class="line"></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #6A737D">// Prepare headers</span></span>
<span class="line"><span style="color: #E1E4E8">    $headers </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> [</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #9ECBFF">'Accept: application/json'</span><span style="color: #E1E4E8">,</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #9ECBFF">'Content-Type: application/json'</span><span style="color: #E1E4E8">,</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #9ECBFF">'X-Postmark-Server-Token: '</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">.</span><span style="color: #E1E4E8"> $server_token,</span></span>
<span class="line"><span style="color: #E1E4E8">    ];</span></span>
<span class="line"></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #6A737D">// Prepare payload</span></span>
<span class="line"><span style="color: #E1E4E8">    $payload </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">json_encode</span><span style="color: #E1E4E8">([</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #9ECBFF">'From'</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=></span><span style="color: #E1E4E8"> $from_email,</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #9ECBFF">'To'</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=></span><span style="color: #E1E4E8"> $to,</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #9ECBFF">'Subject'</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=></span><span style="color: #E1E4E8"> $subject,</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #9ECBFF">'HtmlBody'</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=></span><span style="color: #E1E4E8"> $html_body,</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #9ECBFF">'MessageStream'</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">=></span><span style="color: #E1E4E8"> $message_stream,</span></span>
<span class="line"><span style="color: #E1E4E8">    ], </span><span style="color: #79B8FF">JSON_UNESCAPED_UNICODE</span><span style="color: #E1E4E8">);</span></span>
<span class="line"></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #6A737D">// Log payload for debugging</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #79B8FF">error_log</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">'Postmark API Payload: '</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">.</span><span style="color: #E1E4E8"> $payload);</span></span>
<span class="line"></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #6A737D">// Send email via cURL</span></span>
<span class="line"><span style="color: #E1E4E8">    $url </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #9ECBFF">'https://api.postmarkapp.com/email'</span><span style="color: #E1E4E8">;</span></span>
<span class="line"><span style="color: #E1E4E8">    $ch </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">curl_init</span><span style="color: #E1E4E8">($url);</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #79B8FF">curl_setopt</span><span style="color: #E1E4E8">($ch, </span><span style="color: #79B8FF">CURLOPT_RETURNTRANSFER</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">true</span><span style="color: #E1E4E8">);</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #79B8FF">curl_setopt</span><span style="color: #E1E4E8">($ch, </span><span style="color: #79B8FF">CURLOPT_POST</span><span style="color: #E1E4E8">, </span><span style="color: #79B8FF">true</span><span style="color: #E1E4E8">);</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #79B8FF">curl_setopt</span><span style="color: #E1E4E8">($ch, </span><span style="color: #79B8FF">CURLOPT_POSTFIELDS</span><span style="color: #E1E4E8">, $payload);</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #79B8FF">curl_setopt</span><span style="color: #E1E4E8">($ch, </span><span style="color: #79B8FF">CURLOPT_HTTPHEADER</span><span style="color: #E1E4E8">, $headers);</span></span>
<span class="line"></span>
<span class="line"><span style="color: #E1E4E8">    $response </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">curl_exec</span><span style="color: #E1E4E8">($ch);</span></span>
<span class="line"><span style="color: #E1E4E8">    $response_code </span><span style="color: #F97583">=</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">curl_getinfo</span><span style="color: #E1E4E8">($ch, </span><span style="color: #79B8FF">CURLINFO_HTTP_CODE</span><span style="color: #E1E4E8">);</span></span>
<span class="line"></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #6A737D">// Log API response for debugging</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #79B8FF">error_log</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">'Postmark API Response Code: '</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">.</span><span style="color: #E1E4E8"> $response_code);</span></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #79B8FF">error_log</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">'Postmark API Response: '</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">.</span><span style="color: #E1E4E8"> $response);</span></span>
<span class="line"></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #F97583">if</span><span style="color: #E1E4E8"> (</span><span style="color: #79B8FF">curl_errno</span><span style="color: #E1E4E8">($ch)) {</span></span>
<span class="line"><span style="color: #E1E4E8">        </span><span style="color: #79B8FF">error_log</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">'Postmark API cURL Error: '</span><span style="color: #E1E4E8"> </span><span style="color: #F97583">.</span><span style="color: #E1E4E8"> </span><span style="color: #79B8FF">curl_error</span><span style="color: #E1E4E8">($ch));</span></span>
<span class="line"><span style="color: #E1E4E8">    }</span></span>
<span class="line"></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #79B8FF">curl_close</span><span style="color: #E1E4E8">($ch);</span></span>
<span class="line"></span>
<span class="line"><span style="color: #E1E4E8">    </span><span style="color: #6A737D">// Prevent PHPMailer from sending the email</span></span>
<span class="line"><span style="color: #E1E4E8">    $phpmailer</span><span style="color: #F97583">-></span><span style="color: #B392F0">ClearAllRecipients</span><span style="color: #E1E4E8">();</span></span>
<span class="line"><span style="color: #E1E4E8">    $phpmailer</span><span style="color: #F97583">-></span><span style="color: #B392F0">ClearAttachments</span><span style="color: #E1E4E8">();</span></span>
<span class="line"><span style="color: #E1E4E8">}</span></span>
<span class="line"><span style="color: #B392F0">add_action</span><span style="color: #E1E4E8">(</span><span style="color: #9ECBFF">'phpmailer_init'</span><span style="color: #E1E4E8">, </span><span style="color: #9ECBFF">'rup_postmark_intercept_and_send_email_via_api'</span><span style="color: #E1E4E8">);</span></span>
```PHP

The above script works as intended now, as for how I deploy this as a MU plugin. I am not sure if I should share this, as it is good practice that plugins don’t self-delete and inject for security reasons. I already have one plugin publically that does its thing, makes the changes, and then deletes itself, as already mentioned in this article. I will let people decide on this. If people want this part of the plugin delivery, then ask, and I will write a separate blog post/video about it, as I don’t just use it for this, but the code is only about 70 lines, and it allows anything to be deployed to your mu directory if you upload it this could include a plugin you didn’t expect to upload it.

I can’t stress enough how careful you need to be with the code you get from the internet, even mine. I am not a security expert, and as such, there could be consequences for what I code. They work for me, but others may not. This snippet, if I publish it, could be installed by another plugin. Add the mu-plugin and delete it without you even knowing it was called if the sequences were correct.

![Table listing plugins: Gridpane - Postmark API Interface and WP CLI Login Command Server with descriptions and versions.](https://techarticles.co.uk/wp-content/uploads/2024/12/Gridpane-Postmark-API-Interface.png)

I have to be cautious with some of this stuff for example, I haven’t released details on my ninja updater, which is a bundle installer, custom repo installer, plugin updater and snippet loading plugin because it is basically a GPL charter that can force any plugin to update from your own repo server; it runs snippets that enable features and plugins, allows me to deploy [cloudflare rules](https://webagencyhero.com/cloudflare-waf-rules-v3/) in a single click once details are added, and it is probably the most useful utility, I’ve ever written you’ve seen it in my videos but it will remain mine because I fear it will end up on a GPL site offering updates to premium plugin providers I want to support, automatically removing there branding, there tags and updates from the GPL server.

The below video shows you a little about how the new Gridpane – Postmark API Interface works.

![](https://i.ytimg.com/vi/NBRvFP-9GxU/maxresdefault.jpg)

Thanks for watching