Send Emails with PHP

Use the official isend.ai PHP SDK to send emails with templates via your favorite email provider.

1. Install

Install the isend.ai PHP SDK via Composer:
composer require isend-ai/php-sdk

2. Send an Email Using a Template

Here’s how to send a transactional email using a template ID and dataMapping.
<?php

require_once 'vendor/autoload.php';

use ISend\ISendClient;

// Initialize the client with your API key
$client = new ISendClient('your-api-key-here');

// Prepare email data
$emailData = [
    'template_id' => 124,
    'to' => 'hi@isend.ai',
    'dataMapping' => [
        'name' => 'ISend'
    ]
];

// Send the email
$response = $client->sendEmail($emailData);

print_r($response);

3. Error Handling

The SDK throws an exception on failure. Wrap your logic in a try/catch block for robustness.
try {
    $response = $client->sendEmail([
        'template_id' => 124,
        'to' => 'hi@isend.ai',
        'dataMapping' => [
            'name' => 'ISend'
        ]
    ]);
} catch (Exception $e) {
    echo "Error: " . $e->getMessage();
}

4. GitHub Repo

Check out the repository on GitHub: → View PHP Repo

Requirements

  • PHP 5.6 or higher
  • cURL extension enabled