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

# Installation

> Install the lettr/lettr-php Composer package, instantiate the client with your API key, and store credentials securely in your PHP app.

This page covers installing the `lettr/lettr-php` Composer package and configuring the client for your application. If you haven't already, start with the [Introduction](/quickstart/php/introduction) for a quick overview of what the SDK provides.

## Requirements

* PHP 8.4 or higher
* Guzzle HTTP client 7.5+

## Install the Package

```bash theme={null}
composer require lettr/lettr-php
```

The package installs with no additional dependencies beyond Guzzle HTTP client, which it requires for making API requests. If your project doesn't already have Guzzle, Composer will install it automatically.

## Create a Client

Instantiate the Lettr client with your API key:

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

$lettr = Lettr::client('your-api-key');
```

The static `client()` method returns a configured instance ready to interact with the Lettr API. All subsequent method calls use this client for authentication and requests.

<Tip>
  Get your API key from the [Lettr dashboard](https://app.lettr.com/api-keys). API keys use the `lttr_` prefix followed by 64 hexadecimal characters. See [API Keys](/learn/api-keys/introduction) for details on creating and managing keys.
</Tip>

### Store API Keys Securely

Never hardcode API keys in your source code. Store them in environment variables or configuration files that are excluded from version control:

```php theme={null}
// Using environment variables
$lettr = Lettr::client(getenv('LETTR_API_KEY'));

// Using a config file
$config = require __DIR__ . '/config.php';
$lettr = Lettr::client($config['lettr_api_key']);
```

<Warning>
  Committing API keys to version control is a security risk. Always use environment variables or secure configuration management, and add config files containing secrets to `.gitignore`.
</Warning>

## Available Services

The client provides access to all Lettr API resources through dedicated service objects:

```php theme={null}
$lettr->emails();     // Send emails (HTML, text, templates)
$lettr->domains();    // Manage sending domains
$lettr->templates();  // Manage email templates
$lettr->webhooks();   // Manage webhook endpoints
$lettr->audience();   // Lists, contacts, topics, properties, segments
$lettr->campaigns();  // List, send, and schedule campaigns
$lettr->health();     // API health and auth checks
```

Each service corresponds to a set of API endpoints. For example, `$lettr->emails()` gives you access to:

* Sending emails (HTML, text, templates)
* Building complex emails with the fluent builder
* Attaching files and configuring tracking options

See [Sending Emails](/quickstart/php/sending-emails) for detailed examples of each service.

## Verify Installation

Test that everything is configured correctly using the health check endpoints:

```php theme={null}
// Check API health (no authentication required)
$status = $lettr->health()->check();
echo $status->isHealthy(); // true

// Verify your API key
$auth = $lettr->health()->authCheck();
echo $auth->teamId;
```

The `health()->check()` method verifies that the Lettr API is accessible and operational. It doesn't require authentication, so it's useful for monitoring and debugging connectivity issues.

The `health()->authCheck()` method validates your API key and returns your team ID. If no exception is thrown, your API key is valid and you're ready to send emails.

### Troubleshooting

<AccordionGroup>
  <Accordion title="API key not recognized">
    Verify that your API key starts with `lttr_` and contains 64 hexadecimal characters after the prefix. Check for extra whitespace or newlines when loading from environment variables.
  </Accordion>

  <Accordion title="Connection errors">
    If you see network or transport errors, check your firewall settings. The SDK needs to reach `https://app.lettr.com/api`. If you're behind a corporate proxy, you may need to configure Guzzle with proxy settings.
  </Accordion>

  <Accordion title="Domain verification errors when sending">
    The `from` address must use a domain that is verified in your [Lettr dashboard](https://app.lettr.com/domains). See [Domain Verification](/knowledge-base/troubleshooting/domain-verification) for common issues.
  </Accordion>

  <Accordion title="Emails not arriving">
    Check your [Lettr logs](https://app.lettr.com/logs) to see if the API accepted the request. If the email was accepted but not delivered, see [Delivery Issues](/knowledge-base/troubleshooting/delivery-issues) for diagnosis steps.
  </Accordion>
</AccordionGroup>

## What's Next

<CardGroup cols={2}>
  <Card title="Sending Emails" icon="paper-plane" href="/quickstart/php/sending-emails">
    Learn the different ways to send emails
  </Card>

  <Card title="Templates" icon="file-code" href="/quickstart/php/templates">
    Work with Lettr-managed templates
  </Card>
</CardGroup>
