Quick setup examples
Laravel
Send your first email from a Laravel controller by calling the MailBlastr API with the Http facade.
PHP has an official package — composer require mailblastr/mailblastr — and it works from any Laravel controller or service. The example below shows the dependency-free alternative instead: POST JSON to https://www.mailblastr.com/api/emails with the built-in `Http` facade, a wrapper over Guzzle. See SDKs for the package.
Prerequisites
- A MailBlastr API key.
- A verified domain to send from.
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_xxxxxxxxx2. 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://www.mailblastr.com/api/emails', [
'from' => 'Acme <onboarding@yourdomain.com>',
'to' => ['delivered@mailblastr.dev'],
'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.