Quick setup examples

Laravel

Send your first email from a Laravel controller by calling the MailBlastr API with the Http facade.

Send your first email from a Laravel app by calling the MailBlastr REST API directly. The mailblastr SDK is for Node.js — PHP users POST JSON to https://api.mailblastr.com/emails using Laravel's built-in `Http` facade (a wrapper over Guzzle) from a controller.

Prerequisites

1. Add your API key

Add your key to the application's .env file and read it with the env() helper (or via a config/ entry).

.env
MAILBLASTR_API_KEY=mb_xxxxxxxxx

2. Send email from a controller

Use the Http facade to POST the email body to the MailBlastr API. The easiest way to send is with the html field.

app/Http/Controllers/SendController.php
<?php

namespace App\Http\Controllers;

use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Http;

class SendController extends Controller
{
    public function store(): JsonResponse
    {
        $response = Http::withToken(env('MAILBLASTR_API_KEY'))
            ->post('https://api.mailblastr.com/emails', [
                'from' => 'Acme <onboarding@yourdomain.com>',
                'to' => ['delivered@example.com'],
                'subject' => 'hello world',
                'html' => '<strong>it works!</strong>',
            ]);

        $response->throw();

        return response()->json(['id' => $response->json('id')]);
    }
}
A successful call returns the created email's id. See every supported field in the Send an email reference.