> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mailglyph.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Templates

> Create, list, update, and delete templates with the MailGlyph PHP SDK.

Use a **secret key** client for template methods.

```php theme={null}
<?php

use MailGlyph\MailGlyph;

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

## List templates (`templates->list`)

```php theme={null}
<?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 theme={null}
<?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 theme={null}
<?php

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

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

## Update a template (`templates->update`)

```php theme={null}
<?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 theme={null}
<?php

$client->templates->delete($template->id);
```

See full details in the [Templates API reference](https://docs.mailglyph.com/api-reference/templates/listTemplates.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.