Skip to main content

Prerequisites

To get the most out of this guide, you’ll need to:

1. Install

Composer

To install the bindings via Composer, use the following command on the command line:
shell
composer require sendpost/php-sdk
Or, add the following to composer.json:
composer.json
  "require": {
      "sendpost/php-sdk": "^1.0"
  }
Then run composer install

Manual Installation

Download the files and include autoload.php:
<?php
require_once('/path/to/sendpost/vendor/autoload.php');

2. Getting Started

PHP
<?php
require_once(__DIR__ . '/vendor/autoload.php');
$client = new GuzzleHttp\Client();

$apiInstance = new sendpost\api\EmailApi($client);

$x_sub_account_api_key = 'your_api_key'; // Sub-Account API Key
$email_message = new \sendpost\model\EmailMessage(); 
$email_message->setSubject('Hello World');
$email_message->setHtmlBody('<strong>it works!</strong>');

$from = new \sendpost\model\From();
$from->setEmail('[email protected]');

$to = new \sendpost\model\To();
$to->setEmail('[email protected]');
$email_message->setTo(array($to));
$email_message->setFrom($from);

try {
    $result = $apiInstance->sendEmail($x_sub_account_api_key, $email_message);
    print_r($result);
} catch (Exception $e) {
    echo 'Exception when calling EmailApi->sendEmail: ', $e->getMessage(), PHP_EOL;
}

3. Try it for yourself

PHP Example

See detailed sdk example