PHPackages                             tosend/tosend-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Mail &amp; Notifications](/categories/mail)
4. /
5. tosend/tosend-php

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

tosend/tosend-php
=================

Official PHP SDK for the ToSend email API

00PHP

Since Jan 24Pushed 3mo agoCompare

[ Source](https://github.com/tosend/tosend-php)[ Packagist](https://packagist.org/packages/tosend/tosend-php)[ RSS](/packages/tosend-tosend-php/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

ToSend PHP SDK
==============

[](#tosend-php-sdk)

A simple PHP SDK for the [ToSend](https://tosend.com) email API.

Requirements
------------

[](#requirements)

- PHP 7.4 or higher
- cURL extension

Installation
------------

[](#installation)

### With Composer

[](#with-composer)

```
composer require tosend/tosend-php
```

### Without Composer

[](#without-composer)

This SDK is a single file with no external dependencies. You can use it without Composer:

1. Download [`src/Api.php`](https://github.com/tosend/tosend-php/blob/main/src/Api.php) from this repository
2. Place it anywhere in your project
3. Include it in your code:

```
require_once 'path/to/Api.php';

$tosend = new ToSend\Api('tsend_your_api_key');
```

That's it! The SDK only requires PHP 7.4+ with the `curl` and `json` extensions, which are included in most PHP installations.

Quick Start
-----------

[](#quick-start)

```
use ToSend\Api;

$tosend = new Api('tsend_your_api_key');

$response = $tosend->send([
    'from' => [
        'email' => 'hello@yourdomain.com',
        'name' => 'Your App'
    ],
    'to' => [
        ['email' => 'user@example.com']
    ],
    'subject' => 'Hello from ToSend!',
    'html' => 'Welcome!Thanks for signing up.'
]);

echo $response['message_id'];
```

Usage
-----

[](#usage)

### Send an Email

[](#send-an-email)

```
$response = $tosend->send([
    'from' => [
        'email' => 'hello@yourdomain.com',
        'name' => 'Your App'  // optional
    ],
    'to' => [
        ['email' => 'user@example.com'],
        ['email' => 'another@example.com', 'name' => 'John Doe']
    ],
    'subject' => 'Welcome!',
    'html' => 'Hello',
    'text' => 'Hello'  // optional, auto-generated from HTML if not provided
]);
```

### With CC, BCC, and Reply-To

[](#with-cc-bcc-and-reply-to)

```
$response = $tosend->send([
    'from' => ['email' => 'hello@yourdomain.com'],
    'to' => [['email' => 'user@example.com']],
    'cc' => [['email' => 'cc@example.com']],
    'bcc' => [['email' => 'bcc@example.com']],
    'reply_to' => ['email' => 'support@yourdomain.com', 'name' => 'Support'],
    'subject' => 'Hello',
    'html' => 'Hello World'
]);
```

### With Attachments

[](#with-attachments)

```
$response = $tosend->send([
    'from' => ['email' => 'hello@yourdomain.com'],
    'to' => [['email' => 'user@example.com']],
    'subject' => 'Your Invoice',
    'html' => 'Please find your invoice attached.',
    'attachments' => [
        [
            'type' => 'application/pdf',
            'name' => 'invoice.pdf',
            'content' => base64_encode(file_get_contents('invoice.pdf'))
        ]
    ]
]);
```

### Batch Sending

[](#batch-sending)

Send multiple emails in a single request:

```
$response = $tosend->batch([
    [
        'from' => ['email' => 'hello@yourdomain.com'],
        'to' => [['email' => 'user1@example.com']],
        'subject' => 'Hello User 1',
        'html' => 'Hello!'
    ],
    [
        'from' => ['email' => 'hello@yourdomain.com'],
        'to' => [['email' => 'user2@example.com']],
        'subject' => 'Hello User 2',
        'html' => 'Hello!'
    ]
]);

foreach ($response['results'] as $result) {
    if ($result['status'] === 'success') {
        echo "Sent: " . $result['message_id'] . "\n";
    } else {
        echo "Failed: " . $result['message'] . "\n";
    }
}
```

### Get Account Info

[](#get-account-info)

```
$info = $tosend->getAccountInfo();

echo "Account: " . $info['account']['title'] . "\n";
echo "Emails this month: " . $info['account']['emails_usage_this_month'] . "\n";

foreach ($info['domains'] as $domain) {
    echo $domain['domain_name'] . ": " . $domain['verification_status'] . "\n";
}
```

Error Handling
--------------

[](#error-handling)

```
use ToSend\Api;
use ToSend\ToSendException;

try {
    $response = $tosend->send([
        'from' => ['email' => 'hello@yourdomain.com'],
        'to' => [['email' => 'user@example.com']],
        'subject' => 'Hello',
        'html' => 'Hello'
    ]);
} catch (ToSendException $e) {
    echo "Error: " . $e->getMessage() . "\n";
    echo "Code: " . $e->getCode() . "\n";

    // Get detailed validation errors
    foreach ($e->getErrors() as $field => $errors) {
        foreach ($errors as $key => $message) {
            echo "$field: $message\n";
        }
    }
}
```

API Reference
-------------

[](#api-reference)

### `new Api(string $apiKey)`

[](#new-apistring-apikey)

Create a new Api instance with your API key.

### `send(array $params): array`

[](#sendarray-params-array)

Send a single email. Returns `['message_id' => '...']` on success.

### `batch(array $emails): array`

[](#batcharray-emails-array)

Send multiple emails. Returns `['results' => [...]]` with status for each email.

### `getAccountInfo(): array`

[](#getaccountinfo-array)

Get account and domain information.

### `setBaseUrl(string $url): self`

[](#setbaseurlstring-url-self)

Set a custom API base URL (useful for testing).

License
-------

[](#license)

MIT

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance53

Moderate activity, may be stable

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity12

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/c4caf37249178df0aa7140af2899f1b8608d8cec8180f938afb3f4cd797e1694?d=identicon)[techjewel](/maintainers/techjewel)

---

Top Contributors

[![techjewel](https://avatars.githubusercontent.com/u/1053500?v=4)](https://github.com/techjewel "techjewel (1 commits)")

### Embed Badge

![Health badge](/badges/tosend-tosend-php/health.svg)

```
[![Health](https://phpackages.com/badges/tosend-tosend-php/health.svg)](https://phpackages.com/packages/tosend-tosend-php)
```

###  Alternatives

[tijsverkoyen/css-to-inline-styles

CssToInlineStyles is a class that enables you to convert HTML-pages/files into HTML-pages/files with inline styles. This is very useful when you're sending emails.

5.8k505.3M227](/packages/tijsverkoyen-css-to-inline-styles)[minishlink/web-push

Web Push library for PHP

1.9k12.0M53](/packages/minishlink-web-push)[laravel-notification-channels/twilio

Provides Twilio notification channel for Laravel

2587.7M12](/packages/laravel-notification-channels-twilio)[spatie/url-signer

Generate a url with an expiration date and signature to prevent unauthorized access

4422.3M16](/packages/spatie-url-signer)[mattketmo/email-checker

Throwaway email detection library

2742.0M5](/packages/mattketmo-email-checker)[laravel-notification-channels/discord

Laravel notification driver for Discord.

2371.3M11](/packages/laravel-notification-channels-discord)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
