All guides
Send Email from Symfony
Send emails from Symfony controllers and services
1. Install the SDK
composer require sendpigeon/sendpigeon2. Set your API key
Add your SendPigeon API key to your environment variables:
SENDPIGEON_API_KEY=your_api_key_hereGet your API key from the dashboard.
3. Send your first email
<?php
// src/Controller/ContactController.php
namespace App\Controller;
use SendPigeon\SendPigeon;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
class ContactController extends AbstractController
{
#[Route('/contact', methods: ['POST'])]
public function contact(Request $request): JsonResponse
{
$data = json_decode($request->getContent(), true);
$client = new SendPigeon($_ENV['SENDPIGEON_API_KEY']);
$client->send(
to: $data['email'],
from: 'hello@yourdomain.com',
subject: "Thanks for reaching out, {$data['name']}!",
html: '<h1>We got your message</h1><p>We\'ll get back to you soon.</p>',
);
return $this->json(['success' => true]);
}
}Features
- Service container integration
- Messenger async support
- Twig template support
Ready to send emails?
Get started with 1,000 free emails per month.
Start for free