Skip to content

Instantly share code, notes, and snippets.

@atheken
Created February 20, 2017 21:08
Show Gist options
  • Save atheken/cd377ff03a9a8bb2852b707713f5f340 to your computer and use it in GitHub Desktop.
Save atheken/cd377ff03a9a8bb2852b707713f5f340 to your computer and use it in GitHub Desktop.
A quick template copying script using postmark-php.
<?php
// You should have already installed wildbit/postmark-php via Composer.
// This script should be run from the root directory where the 'vendor'
// folder is created by Composer.
require_once('./vendor/autoload.php');
use Postmark\PostmarkClient;
use Postmark\Models\PostmarkException;
try{
// Pay special attention to the Server source and destination tokens here:
$sourceClient = new PostmarkClient('<source server token>');
$destinationClient = new PostmarkClient('<destination server token>');
$allTemplates = $sourceClient->listTemplates(300)->templates;
foreach($allTemplates as $template){
$templateContent = $sourceClient->getTemplate($template->templateid);
$destinationClient->createTemplate($templateContent->name, $templateContent->subject, $templateContent->htmlbody, $templateContent->textbody);
echo "Copied `$templateContent->name`\r\n";
}
}catch(PostmarkException $ex){
echo $ex->httpStatusCode;
echo $ex->message;
echo $ex->postmarkApiErrorCode;
}catch(Exception $generalException){
echo "Something bad happened, but probably not an issue with Postmark. $generalException";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment