Skip to main content
Use a secret key client for template methods.
<?php

use MailGlyph\MailGlyph;

$client = new MailGlyph($_ENV['MAILGLYPH_SECRET_KEY']);

List templates (templates->list)

<?php

$page = $client->templates->list([
    'limit' => 20,
    'type' => 'TRANSACTIONAL',
    'search' => 'welcome',
]);

echo $page['total'] . PHP_EOL;
echo $page['totalPages'] . PHP_EOL;
echo count($page['data']) . PHP_EOL;

Create a template (templates->create)

<?php

$template = $client->templates->create([
    'name' => 'Welcome',
    'subject' => 'Welcome to MailGlyph',
    'body' => '<h1>Welcome</h1><p>Thanks for joining us.</p>',
    'type' => 'TRANSACTIONAL',
]);

echo $template->id . PHP_EOL;
echo $template->name . PHP_EOL;

Get one template (templates->get)

<?php

$fetched = $client->templates->get($template->id);

echo $fetched->subject . PHP_EOL;
echo $fetched->type . PHP_EOL;

Update a template (templates->update)

<?php

$updated = $client->templates->update($template->id, [
    'subject' => 'Welcome to MailGlyph!',
    'body' => '<h1>Welcome!</h1><p>We are glad to have you.</p>',
]);

echo $updated->subject . PHP_EOL;

Delete a template (templates->delete)

<?php

$client->templates->delete($template->id);
See full details in the Templates API reference.