# PHP

> Send your first email from PHP using cURL against the MailBlastr API.

MailBlastr has no PHP SDK — you send email by POSTing JSON to `https://api.mailblastr.com/emails`. The examples below use PHP's built-in cURL extension, which ships with most PHP installs.

## Prerequisites

- A MailBlastr [API key](https://www.mailblastr.com/docs/api-keys/overview).
- A [verified domain](https://www.mailblastr.com/docs/domains/managing) to send from.
- PHP with the `curl` extension enabled.

## 1. Set your API key

Read your API key from the environment rather than hardcoding it. Set `MAILBLASTR_API_KEY` in your environment (or your framework's `.env`).

**.env**

```sh
MAILBLASTR_API_KEY=mb_xxxxxxxxx
```

## 2. Send email using HTML

The easiest way to send an email is with the `html` field.

**index.php**

```php
<?php

$apiKey = getenv('MAILBLASTR_API_KEY');

$payload = json_encode([
  'from' => 'Acme <onboarding@yourdomain.com>',
  'to' => ['delivered@example.com'],
  'subject' => 'hello world',
  'html' => '<strong>it works!</strong>',
]);

$ch = curl_init('https://api.mailblastr.com/emails');
curl_setopt_array($ch, [
  CURLOPT_POST => true,
  CURLOPT_POSTFIELDS => $payload,
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_HTTPHEADER => [
    'Authorization: Bearer ' . $apiKey,
    'Content-Type: application/json',
  ],
]);

$response = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch);

if ($status >= 200 && $status < 300) {
  $data = json_decode($response, true);
  echo $data['id'];
} else {
  echo 'Error: ' . $response;
}
```

> **Note:** A successful call returns the created email's `id`. See the full set of body fields in the [Send an email](https://www.mailblastr.com/docs/api/emails-send) reference.

## Laravel / Symfony

In a framework, you can use the HTTP client you already have — Laravel's `Http` facade or Symfony's `HttpClient` — pointing at `https://api.mailblastr.com/emails` with the same `Authorization: Bearer` header. The request body shape is identical to the cURL example above.
