> ## 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.

# Contacts

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

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

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

use MailGlyph\MailGlyph;

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

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

Use cursor pagination for large lists:

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

$page1 = $client->contacts->list([
    'limit' => 50,
    'subscribed' => true,
    'search' => 'john',
]);

echo count($page1['data']) . PHP_EOL;
var_dump($page1['hasMore']);
echo $page1['cursor'] . PHP_EOL;
```

Fetch the next page with `cursor`:

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

if ($page1['hasMore'] && $page1['cursor'] !== null) {
    $page2 = $client->contacts->list([
        'limit' => 50,
        'cursor' => $page1['cursor'],
    ]);

    echo count($page2['data']) . PHP_EOL;
}
```

## Create a contact (`contacts->create`)

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

$created = $client->contacts->create([
    'email' => 'user@example.com',
    'subscribed' => true,
    'data' => [
        'firstName' => 'John',
        'plan' => 'premium',
    ],
]);

echo $created->id . PHP_EOL;
var_dump($created->meta['isNew'] ?? null);
var_dump($created->meta['isUpdate'] ?? null);
```

## Get one contact (`contacts->get`)

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

$contact = $client->contacts->get($created->id);

echo $contact->email . PHP_EOL;
var_dump($contact->subscribed);
```

## Update a contact (`contacts->update`)

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

$updated = $client->contacts->update($created->id, [
    'subscribed' => false,
    'data' => [
        'plan' => 'pro',
    ],
]);

var_dump($updated->subscribed);
echo $updated->data['plan'] . PHP_EOL;
```

## Count contacts (`contacts->count`)

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

$subscribedCount = $client->contacts->count(['subscribed' => true]);
echo $subscribedCount . PHP_EOL;
```

## Delete a contact (`contacts->delete`)

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

$client->contacts->delete($created->id);
```

See full details in the [Contacts API reference](https://docs.mailglyph.com/api-reference/contacts/listContacts.md).


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