# WordPress

The official [Lettermint plugin](https://wordpress.org/plugins/lettermint/) hooks into WordPress's `wp_mail()` function and delivers every message your site sends through Lettermint's European infrastructure. Because Lettermint runs entirely inside the EU and processes mail in line with GDPR, your WordPress transactional email stays within Europe.

Most people install the plugin and configure it from **Settings** → **Lettermint** in the WordPress admin, and that is all a single site needs. This guide is for the next step: driving the plugin from **WP-CLI** so you can configure, test, and monitor Lettermint without opening the browser, and roll it out across many sites at once. That makes it a good fit for agencies and teams that manage a lot of WordPress installations.

## Requirements

The plugin needs WordPress 6.4 or higher and PHP 7.4 or higher, plus a Project API token from your [project settings](https://app.lettermint.co/projects).

## Install from the command line

Install and activate the plugin with a single WP-CLI command:

```bash
wp plugin install lettermint --activate
```

Once the API token is set, every WordPress email routes through Lettermint automatically. There are no theme or plugin code changes to make.

## Configure with constants instead of the database

The settings screen writes configuration to the database, which is fine for one site. For version-controlled or scripted setups, define the same values as constants in `wp-config.php`. This keeps your token out of the database and makes configuration portable across staging and production:

```php title="wp-config.php"
define( 'LETTERMINT_API_TOKEN', 'lm_...' );
define( 'LETTERMINT_FROM_EMAIL', 'hello@example.com' );
define( 'LETTERMINT_FROM_NAME', 'Example Store' );
```

Or set them directly with WP-CLI, which is handy in deploy scripts:

```bash
wp config set LETTERMINT_API_TOKEN lm_...
```

Constants take precedence over anything saved in the settings screen. Run `wp lettermint info` to confirm which value is active and where it comes from. The full set of constants:

| Constant | Purpose |
|----------|---------|
| `LETTERMINT_API_TOKEN` | Project API token (required) |
| `LETTERMINT_FROM_EMAIL` | Default sender address |
| `LETTERMINT_FROM_NAME` | Default sender name (falls back to the site name) |
| `LETTERMINT_FORCE_EMAIL` | Override sender addresses set by other plugins |
| `LETTERMINT_FORCE_FROM_NAME` | Override sender names set by other plugins |
| `LETTERMINT_FORCE_HTML` | Send all mail as HTML |
| `LETTERMINT_ROUTE_SLUG` | Send through a specific [route](/platform/projects-and-routes/routes) |
| `LETTERMINT_TAG` | Apply a [tag](/platform/emails/tags) to every email |
| `LETTERMINT_LOG_LEVEL` | Logging level |
| `LETTERMINT_LOG_RETENTION_DAYS` | Days to keep logs |

## WP-CLI command reference

The plugin registers a `wp lettermint` command for managing and debugging the integration from the terminal.

| Command | What it does |
|---------|--------------|
| `wp lettermint status` | Check that your API token is valid |
| `wp lettermint test <email>` | Send a test email through Lettermint |
| `wp lettermint info` | Show the resolved configuration and where each value comes from |
| `wp lettermint logs` | List recent log entries (`--type`, `--search`, `--number`, `--format`) |
| `wp lettermint stats` | Show a summary of the log |
| `wp lettermint prune --days=30` | Delete log entries older than N days |

### Verify the connection

```bash
wp lettermint status
```

### Send a live test email

```bash
wp lettermint test you@example.com
```

### Inspect the resolved configuration

`info` reports every setting and its source (constant, environment variable, or settings screen), which is the fastest way to see why a value is what it is:

```bash
wp lettermint info
```

### Query the logs

`logs` accepts `--type`, `--search`, `--number`, and `--format` so you can filter and pipe the output:

```bash
# Most recent entries
wp lettermint logs

# The last 50 failed emails as JSON
wp lettermint logs --type=error --number=50 --format=json

# Find entries by recipient or subject
wp lettermint logs --search="invoice"
```

### Review statistics and prune

```bash
wp lettermint stats
wp lettermint prune --days=30
```

## Roll out across many WordPress sites

The plugin resolves each setting from a PHP constant first, then an environment variable, and only then the database. That order makes a containerised fleet effortless: set the `LETTERMINT_*` variables on a WordPress container and the site sends through Lettermint the moment it boots, with nothing written to the settings screen, `wp-config.php`, or the database.

Keep the token in a `.env` file that Docker Compose reads automatically, and pass the variables to your WordPress service:

```dotenv title=".env"
LETTERMINT_API_TOKEN=lm_...
```

```yaml title="docker-compose.yml"
services:
  wordpress:
    image: wordpress:php8.3-apache
    environment:
      LETTERMINT_API_TOKEN: ${LETTERMINT_API_TOKEN}
      LETTERMINT_FROM_EMAIL: hello@example.com
      LETTERMINT_TAG: client-one
    volumes:
      - wp:/var/www/html
    # plus your database service and the usual WORDPRESS_DB_* settings

  # WP-CLI helper for install, activation, and the lettermint commands
  wpcli:
    image: wordpress:cli
    environment:
      LETTERMINT_API_TOKEN: ${LETTERMINT_API_TOKEN}
    volumes:
      - wp:/var/www/html

volumes:
  wp:
```

Install and activate the plugin once, then verify the container from the WP-CLI helper:

```bash
docker compose run --rm wpcli wp plugin install lettermint --activate
docker compose run --rm wpcli wp lettermint status
docker compose run --rm wpcli wp lettermint test ops@example.com
```

Running many sites is then one service per site, all on the same official WordPress image. Give each its own `LETTERMINT_TAG` or `LETTERMINT_ROUTE_SLUG` while they share a single token, so you can filter each site's mail in your dashboard. Install the plugin per site with the same `wpcli` helper shown above, or mount it into each container:

```yaml title="docker-compose.yml"
services:
  client-one:
    image: wordpress:php8.3-apache
    environment:
      LETTERMINT_API_TOKEN: ${LETTERMINT_API_TOKEN}
      LETTERMINT_TAG: client-one

  client-two:
    image: wordpress:php8.3-apache
    environment:
      LETTERMINT_API_TOKEN: ${LETTERMINT_API_TOKEN}
      LETTERMINT_ROUTE_SLUG: client-two-route
```

## Keep deliverability high

Routing through Lettermint handles delivery, but inbox placement still depends on your DNS. Verify each sending domain and publish the records Lettermint gives you:

- [Verify your sending domain](/platform/domains/introduction) with DKIM
- [Configure SPF](/platform/domains/spf) so receivers trust your mail

## Logging and privacy

The plugin keeps a local log you can read with `wp lettermint logs` or under **Settings** → **Lettermint**. Pick the level that matches your privacy needs. Metadata-only mode is a good default when you want an audit trail without storing message content:

| Level | What is recorded |
|-------|------------------|
| Disabled | Nothing |
| Errors only | Only failed sends |
| Metadata only | Recipient, subject, sender, and headers, without the message body |
| Full | Everything, including the email content |

Set **Log Retention** to prune old entries automatically after a number of days, or to `0` to keep logs indefinitely. You can also prune on demand with `wp lettermint prune`.

## Troubleshooting

If email is not arriving:

1. Run `wp lettermint status` to confirm the token is valid
2. Send `wp lettermint test you@example.com` to trigger a live send
3. Check `wp lettermint logs --type=error` for recent failures
4. Run `wp lettermint info` to confirm the from address and route resolve as expected

The plugin also detects other mail or SMTP plugins that also hook into `wp_mail()` and warns you in the admin. Only one mailer should handle `wp_mail()` at a time, so deactivate the others.

## FAQ

<details>
<summary>Does Lettermint keep WordPress email data in the EU?</summary>

Yes. Lettermint runs exclusively on European infrastructure and processes email in line with GDPR, so transactional mail from your WordPress site is handled inside the EU.

</details>

<details>
<summary>Can I set up the plugin without the WordPress admin UI?</summary>

Yes. Define the `LETTERMINT_*` constants in `wp-config.php` or set them with `wp config set`, then verify with `wp lettermint status`. Nothing needs to be entered in the settings screen.

</details>

<details>
<summary>How do I configure Lettermint on many WordPress sites at once?</summary>

Store the API token in your environment and script the rollout with WP-CLI. The provisioning loop above installs, activates, configures, and tests every site without touching the admin for any of them.

</details>

<details>
<summary>How do I confirm WordPress email works from the command line?</summary>

Run `wp lettermint status` to validate the token and `wp lettermint test you@example.com` to send a live test. Use `wp lettermint logs --type=error` to see any failures.

</details>

<details>
<summary>Does the plugin use SMTP?</summary>

No. The plugin intercepts `wp_mail()` through WordPress's `pre_wp_mail` filter and sends via the Lettermint API, so it leaves your PHPMailer and SMTP settings untouched. If you specifically need SMTP relay, follow the [SMTP guide](/guides/send-email-with-smtp) instead. Both deliver through the same EU infrastructure.

</details>

## Next Steps

<CardGroup cols={2}>
    <Card title="Tags" icon="tag" href="/platform/emails/tags">
        Organize and filter emails with tags.
    </Card>
    <Card title="Tracking" icon="chart-line" href="/platform/emails/tracking/introduction">
        Track opens, clicks, and deliverability.
    </Card>
    <Card title="Webhooks" icon="webhook" href="/platform/webhooks/introduction">
        Receive real-time delivery notifications.
    </Card>
    <Card title="SMTP Alternative" icon="envelope" href="/guides/send-email-with-smtp">
        Send via SMTP instead of the plugin.
    </Card>
</CardGroup>

<Card title="WordPress Plugin Directory" icon="wordpress" href="https://wordpress.org/plugins/lettermint/">
    View the plugin listing, changelog, and reviews on WordPress.org.
</Card>
