> ## Documentation Index
> Fetch the complete documentation index at: https://jetemail.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# PHP

> Official JetEmail PHP SDK for transactional email

# PHP SDK

The **[jetemail/jetemail-php](https://packagist.org/packages/jetemail/jetemail-php)** package is the official PHP SDK for JetEmail transactional email (MIT license, **PHP 8.1+**).

Create a **transactional** API key in the dashboard: **Outbound** → **Keys** → Add API key. Use that key with the SDK.

<Note>For Laravel projects, use the dedicated [Laravel SDK](/transactional-email/sdk/laravel) which includes Mail driver integration and webhook support.</Note>

## Installation

```bash theme={null}
composer require jetemail/jetemail-php
```

Package on Packagist: [jetemail/jetemail-php](https://packagist.org/packages/jetemail/jetemail-php).

## Quick start

```php theme={null}
use JetEmail\JetEmail;
use JetEmail\SendEmailOptions;

$client = new JetEmail('your-transactional-api-key');

$result = $client->email->send(new SendEmailOptions(
    from: 'Your App <hello@yourdomain.com>',
    to: 'user@example.com',
    subject: 'Welcome!',
    html: '<h1>Welcome!</h1>',
));
```

Use a `from` address on a **verified domain** (see [Getting started](/transactional-email/getting-started)).

## Constructor

```php theme={null}
// API key string
$client = new JetEmail('your-transactional-api-key');

// Or with options
$client = new JetEmail(
    apiKey: 'your-transactional-api-key',
    baseUrl: 'https://api.jetemail.com', // optional
);
```

## `$client->email->send(options)`

Send a single email.

| Field                  | Required | Description                              |
| ---------------------- | -------- | ---------------------------------------- |
| `from`                 | ✓        | Sender, e.g. `"Name <email@domain.com>"` |
| `to`                   | ✓        | Recipient(s), string or array (max 50)   |
| `subject`              | ✓        | Subject line                             |
| `html`                 | \*       | HTML body (need `html` and/or `text`)    |
| `text`                 | \*       | Plain text (need `html` and/or `text`)   |
| `cc`, `bcc`, `replyTo` |          | Recipients (max 50 each)                 |
| `headers`              |          | Custom headers array                     |
| `attachments`          |          | Attachments (max 40MB total)             |

Response shape: `['id' => string, 'response' => string]`.

## `$client->batch->send(emails)`

Send up to **100** emails in one request. Returns `summary` (`total`, `successful`, `failed`) and `results` per message.

```php theme={null}
$result = $client->batch->send([
    new SendEmailOptions(
        from: 'you@example.com',
        to: 'alice@example.com',
        subject: 'Hello Alice',
        html: '<p>Hi Alice!</p>',
    ),
    new SendEmailOptions(
        from: 'you@example.com',
        to: 'bob@example.com',
        subject: 'Hello Bob',
        html: '<p>Hi Bob!</p>',
    ),
]);
```

## Attachments

```php theme={null}
use JetEmail\Attachment;

$result = $client->email->send(new SendEmailOptions(
    from: 'you@example.com',
    to: 'recipient@example.com',
    subject: 'Invoice',
    html: '<p>Please find your invoice attached.</p>',
    attachments: [
        Attachment::fromPath('/path/to/invoice.pdf'),
        Attachment::fromContent('Hello World', 'hello.txt'),
    ],
));
```

## Error handling

```php theme={null}
use JetEmail\JetEmailException;

try {
    $client->email->send(new SendEmailOptions(...));
} catch (JetEmailException $e) {
    echo $e->getMessage();
    echo $e->statusCode;
    echo $e->response;
}
```

Common status codes: **400** invalid request, **401** bad/missing API key, **500** server error.

***

For additional examples and the full option list, see the **[Packagist package page](https://packagist.org/packages/jetemail/jetemail-php)**. REST details: [API reference](/api-reference/introduction).
