Groundmail with Symfony Mailer
Use groundmail/symfony-mailer for a first-class Symfony Mailer transport over the Groundmail HTTP API.
For Laravel apps, prefer groundmail/laravel — it uses this transport under the hood.
1. Install
composer require groundmail/symfony-mailerexport GROUNDMAIL_API_KEY=gm_your_key_here2. Send with Mailer
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:
# 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:
$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 directly.