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

# Managing Domains

> List, add, verify, and delete sending domains and check DKIM and CNAME status with the domains service in the Lettr PHP SDK.

Before you can send email, the sending domain must be verified in Lettr. The `$lettr->domains()` service lets you manage domains programmatically — useful for multi-tenant apps that onboard customer domains, or for automating DNS verification checks.

For the concepts behind domain setup (SPF, DKIM, DMARC, tracking domains), see [Sending Domains](/learn/domains/sending-domains).

## List Domains

```php theme={null}
$domains = $lettr->domains()->list();

foreach ($domains as $domain) {
    echo $domain->domain;                    // example.com
    echo $domain->status->value;             // 'pending', 'approved'
    echo $domain->canSend;                   // true/false
    echo $domain->dkimStatus?->value;        // 'valid', 'invalid', etc.
    echo $domain->cnameStatus?->value;       // 'valid', 'invalid', etc.
}
```

<Card title="API Reference" icon="book" href="/api-reference/domains/list-domains">
  GET /domains
</Card>

## Add a Domain

```php theme={null}
use Lettr\ValueObjects\DomainName;

$result = $lettr->domains()->create('example.com');
// or pass a DomainName value object
$result = $lettr->domains()->create(new DomainName('example.com'));

echo $result->domain;        // example.com
echo $result->status->value; // 'pending'
echo $result->statusLabel;   // "Pending Review"

// DKIM configuration to publish in DNS
if ($result->dkim !== null) {
    echo $result->dkim->selector;      // DKIM selector (e.g. "scph0226")
    echo $result->dkim->publicKey;     // DKIM public key
    echo $result->dkim->headers;       // Signed headers (e.g. "from:to:subject:date")
    echo $result->dkim->signingDomain; // Signing domain
}
```

Adding a domain returns the DNS records you need to publish. Once published, call `verify()` to check them.

<Card title="API Reference" icon="book" href="/api-reference/domains/create-domain">
  POST /domains
</Card>

## Get Domain Details

```php theme={null}
$domain = $lettr->domains()->get('example.com');

echo $domain->domain;
echo $domain->status->value;
echo $domain->canSend;
echo $domain->dkimStatus?->label();   // DnsStatus enum
echo $domain->cnameStatus?->label();
echo $domain->dmarcStatus?->label();
echo $domain->spfStatus?->label();
echo $domain->trackingDomain;
echo $domain->createdAt;

// DKIM record helpers
if ($domain->dkim !== null) {
    echo $domain->dkim->recordName('example.com'); // Full DNS record name
    echo $domain->dkim->recordValue();             // Full DNS record value
}
```

<Card title="API Reference" icon="book" href="/api-reference/domains/get-domain">
  GET /domains/{domain}
</Card>

## Verify Domain DNS

After publishing the DNS records, trigger a verification check:

```php theme={null}
$verification = $lettr->domains()->verify('example.com');

if ($verification->isFullyVerified()) {
    echo "Domain is ready to send!";
} else {
    // Individual record statuses
    echo $verification->dkimStatus->label();   // "Valid", "Invalid", "Missing", etc.
    echo $verification->cnameStatus->label();
    echo $verification->dmarcStatus->label();
    echo $verification->spfStatus->label();

    // Specific DNS record errors
    if ($verification->hasErrors()) {
        foreach ($verification->errors() as $type => $error) {
            echo "$type: $error";
        }
    }
}
```

<Tip>
  DNS changes can take time to propagate. If verification fails immediately after publishing records, wait a few minutes and try again. See [Domain Verification troubleshooting](/knowledge-base/troubleshooting/domain-verification) for common issues.
</Tip>

<Card title="API Reference" icon="book" href="/api-reference/domains/verify-domain">
  POST /domains/{domain}/verify
</Card>

## Delete a Domain

```php theme={null}
$lettr->domains()->delete('example.com');
```

<Warning>
  Deleting a domain stops all sending from that domain immediately. Emails sent from a deleted domain will fail with a validation error.
</Warning>

<Card title="API Reference" icon="book" href="/api-reference/domains/delete-domain">
  DELETE /domains/{domain}
</Card>

## What's Next

<CardGroup cols={2}>
  <Card title="Sending Domains" icon="globe" href="/learn/domains/sending-domains">
    DNS setup: SPF, DKIM, DMARC
  </Card>

  <Card title="Webhooks" icon="bell" href="/quickstart/php/webhooks">
    Receive delivery and engagement events
  </Card>
</CardGroup>
