# Groundmail with Symfony Mailer

Use [`groundmail/symfony-mailer`](https://packagist.org/packages/groundmail/symfony-mailer) for a first-class [Symfony Mailer](https://symfony.com/doc/current/mailer.html) transport over the Groundmail HTTP API.

For Laravel apps, prefer [`groundmail/laravel`](https://docs.groundmail.dev/frameworks/laravel) — it uses this transport under the hood.

## 1. Install

```bash
composer require groundmail/symfony-mailer
```

```bash
export GROUNDMAIL_API_KEY=gm_your_key_here
```

## 2. Send with Mailer

```php
use Groundmail\Client;
use Groundmail\Symfony\Transport\GroundmailTransport;
use Symfony\Component\Mailer\Mailer;
use Symfony\Component\Mime\Email;

$mailer = new Mailer(new GroundmailTransport(new Client(getenv('GROUNDMAIL_API_KEY'))));

$email = (new Email())
    ->from('noreply@yourdomain.com')
    ->to('user@example.com')
    ->subject('Your receipt')
    ->html('<p>Thanks for your purchase.</p>')
    ->text('Thanks for your purchase.');

$mailer->send($email);
```

## 3. Framework DSN

Register the factory as a `mailer.transport_factory` service, then:

```yaml
# config/packages/mailer.yaml
framework:
  mailer:
    dsn: 'groundmail+api://%env(GROUNDMAIL_API_KEY)%@default'
```

Supported schemes: `groundmail`, `groundmail+api`. Optional query: `?base_url=https://api.groundmail.dev`.

## Headers

Set Groundmail headers on the Symfony message:

```php
$email->getHeaders()->addTextHeader('X-Groundmail-Tag', 'product=symfony');
$email->getHeaders()->addTextHeader('X-Groundmail-Idempotency-Key', 'receipt-123');
```

| Header | Purpose |
|--------|---------|
| `X-Groundmail-Tag` | `name=value` (repeatable) |
| `X-Groundmail-Idempotency-Key` | Idempotency key |
| `X-Groundmail-Scheduled-At` | ISO 8601 schedule |

## Direct PHP SDK

If you don't need Symfony Mailer, use the [PHP SDK](https://docs.groundmail.dev/sdks/php) directly.

## Source

[Groundmail/groundmail-symfony-mailer](https://github.com/Groundmail/groundmail-symfony-mailer)
