Quick setup examples

Symfony

Send your first email from a Symfony controller using the Symfony HttpClient against the MailBlastr API.

The mailblastr SDK is for Node.js — PHP users send email by POSTing JSON to https://api.mailblastr.com/emails. The example below uses Symfony's HttpClient component, which you can inject into any controller or service.

Prerequisites

1. Install the HTTP client

Install the Symfony HttpClient component with Composer.

Composer
composer require symfony/http-client

2. Configure your API key

In your .env.local file, which you can create if needed, add your MailBlastr API key. Never commit this file.

.env.local
MAILBLASTR_API_KEY=mb_xxxxxxxxx

3. Send your first email

Inject the HttpClientInterface into a controller and POST the email body. The easiest way to send is with the html field.

src/Controller/EmailController.php
<?php

namespace App\Controller;

use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Contracts\HttpClient\HttpClientInterface;

class EmailController
{
    public function __construct(
        private readonly HttpClientInterface $client,
    ) {
    }

    #[Route('/send', name: 'send_email')]
    public function send(): JsonResponse
    {
        $response = $this->client->request('POST', 'https://api.mailblastr.com/emails', [
            'auth_bearer' => $_ENV['MAILBLASTR_API_KEY'],
            'json' => [
                'from' => 'Acme <onboarding@yourdomain.com>',
                'to' => ['delivered@example.com'],
                'subject' => 'Hello world',
                'html' => '<strong>it works!</strong>',
            ],
        ]);

        return new JsonResponse($response->toArray());
    }
}
A successful call returns the created email's id. See Send an email for the complete request body.