# Groundmail with PHP

Use the PHP SDK in Laravel, Symfony, WordPress plugins, or any server-side PHP app where your API key can stay private.

## 1. Install the SDK

```bash
composer require groundmail/groundmail
```

## 2. Configure your API key

```bash
export GROUNDMAIL_API_KEY=gm_your_key_here
```

## 3. Send an email

```php
<?php

use Groundmail\Client;

$tx = new Client(getenv('GROUNDMAIL_API_KEY'));

$result = $tx->emails->send([
    'from' => 'ops@yourdomain.com',
    'to' => 'user@example.com',
    'subject' => 'Your receipt',
    'html' => '<p>Thanks for your purchase.</p>',
]);

echo $result['id'], ' ', $result['status'], PHP_EOL;
```

## Resources

The client includes thin wrappers for common API resources:

- `$tx->emails` — send, batch, list, cancel, resend, test webhooks, deliverability insights
- `$tx->domains` — create, verify, apply DNS, update, delete
- `$tx->webhooks` — CRUD for webhook endpoints
- `$tx->templates` — CRUD plus publish
- `$tx->suppressions` — list, create, remove
- `$tx->validate($email)` and `$tx->validateBatch($emails)` — check addresses before you accept them ([validation](https://docs.groundmail.dev/validation)); `mailboxCheck: true` also confirms the mailbox exists

See the [API reference](https://docs.groundmail.dev/emails) for request fields. The PHP SDK accepts the same JSON shapes as the REST API.

For Symfony Mailer, use [`groundmail/symfony-mailer`](https://docs.groundmail.dev/frameworks/symfony). For Laravel, use [`groundmail/laravel`](https://docs.groundmail.dev/frameworks/laravel) (config, container binding, Facade — built on the Symfony transport).

## Source

Package source lives in [Groundmail/groundmail-php](https://github.com/Groundmail/groundmail-php) (Packagist requires `composer.json` at repo root).
