Prerequisites
To get the most out of this guide, you’ll need to:
You can find your API keys in your SendPost
Dashboard. Make sure to use your Sub-Account API Key
for sending emails.
1. Install
Composer
To install the bindings via Composer, use the following command on the command line:
composer require sendpost/php-sdk
Or, add the following to composer.json:
"require": {
"sendpost/php-sdk": "*"
}
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
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;
}
Make sure your sender email domain is verified in your SendPost account before
sending emails.
3. Next Steps
Explore more examples and use cases: