1. Go to this page and download the library: Download anypost/anypost-php library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
anypost / anypost-php example snippets
use Anypost\Anypost;
$client = new Anypost('ap_your_api_key');
$email = $client->email->send([
'from' => 'YourCo <[email protected]>',
'to' => ['[email protected]'],
'subject' => 'Welcome to Anypost',
'html' => '<p>Hello, inbox!</p>',
]);
echo $email->id;
$domain = $client->domains->create(['name' => 'example.com']);
foreach ($domain->dns_records as $record) {
echo "{$record->type} {$record->name} -> {$record->value}\n";
}
$checked = $client->domains->verify($domain->id);
if ($checked->status !== 'verified') {
// verify returns the current domain even while pending; it does not throw
echo $checked->verification_failure;
}
$created = $client->apiKeys->create([
'name' => 'Production server',
'permissions' => 'send_only',
'allowed_domains' => ['example.com'],
]);
echo $created->key; // never retrievable again
$page = $client->domains->list(['limit' => 50]);
$page->data; // this page's items
$page->hasMore; // whether another page exists
$page->nextCursor; // pass as "after" to fetch it yourself
foreach ($client->domains->list() as $domain) {
echo $domain->name; // every domain, across all pages
}
use Anypost\Exceptions\AnypostException;
use Anypost\Exceptions\RateLimitException;
use Anypost\Exceptions\ValidationException;
try {
$client->email->send($message);
} catch (ValidationException $e) {
print_r($e->getErrors()); // ['from' => ['The from field is