PHP code example of sendpost / sendpost_php_sdk

1. Go to this page and download the library: Download sendpost/sendpost_php_sdk 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/ */

    

sendpost / sendpost_php_sdk example snippets




   $client = new GuzzleHttp\Client();

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

  $x_sub_account_api_key = 'your_api_key'; // string | Sub-Account API Key
  $email_message = new \sendpost\model\EmailMessage(); 
  $email_message->setSubject('Hello World');
  $email_message->setHtmlBody('<strong>it works!</strong>');
  $email_message->setIppool('PiedPiper');
  $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;
  }


   $client = new GuzzleHttp\Client();

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

  $x_sub_account_api_key = 'your_api_key'; // string | Sub-Account API Key
  $email_message = new \sendpost\model\EmailMessage(); 
  $email_message->setSubject('Hello World');
  $email_message->setHtmlBody('<strong>it works!</strong>');
  $email_message->setIppool('PiedPiper');
  $from = new \sendpost\model\From();
  $from->setEmail('[email protected]');

  $cc = new \sendpost\model\CopyTo();
  $cc->setEmail('[email protected]');
  $to->setCc(array($cc));
  $bcc = new \sendpost\model\CopyTo();
  $bcc->setEmail('[email protected]');
  $to->setBcc(array($bcc));

  $email_message->setTemplate('Welcome Mail');

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

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


   $client = new GuzzleHttp\Client();

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

  $x_sub_account_api_key = 'your_api_key'; 

  $r_suppression = new \sendpost\model\RSuppression();
  $suppression_email = new \sendpost\model\SuppressionEmail();
  $suppression_email->setEmail('richard@piedpiper_fake.com');

  $r_suppression->setHardBounce(array($suppression_email));

  // fields are optional, but you have to send at least one of them.

  // $r_suppression->setManual(array($suppression_email));
  // $r_suppression->setSpamComplaint(array($suppression_email));
  // $r_suppression->setUnsubscribe(array($suppression_email));

  try {
      $result = $apiInstance->createSuppressions($x_sub_account_api_key, $r_suppression);
      echo json_encode($result);
  } catch (Exception $e) {
      echo 'Exception when calling SuppressionApi->createSuppressions: ', $e->getMessage(), PHP_EOL;
  }

   $client = new GuzzleHttp\Client();

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

  $x_sub_account_api_key = 'your_api_key'; 

  $offset = 0;
  $limit = 10;
  $search = null;
  $from = '2023-06-07';
  $to = '2023-08-02';

  try {
      $result = $apiInstance->getSuppressions($x_sub_account_api_key, $offset, $limit, $search, $from, $to);
      echo json_encode($result);
  } catch (Exception $e) {
      echo 'Exception when calling SuppressionApi->getSuppressions: ', $e->getMessage(), PHP_EOL;
  }

   $client = new GuzzleHttp\Client();

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

  $x_sub_account_api_key = 'your_api_key'; 

  $rd_suppression = new \sendpost\model\RDSuppression();
  $suppression_email = new \sendpost\model\SuppressionEmail();
  $suppression_email->setEmail('richard@piedpiper_fake.com');

  $rd_suppression->setSuppressions(array($suppression_email));

  try {
      $result = $apiInstance->deleteSuppression($x_sub_account_api_key, $rd_suppression);
      echo json_encode($result);
  } catch (Exception $e) {
      echo 'Exception when calling SuppressionApi->deleteSuppression: ', $e->getMessage(), PHP_EOL;
  }

   $client = new GuzzleHttp\Client();

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

  $x_sub_account_api_key = 'your_api_key'; 

  $from = '2023-06-07';
  $to = '2023-08-02';

  try {
      $result = $apiInstance->count($x_sub_account_api_key, $from, $to);
      echo json_encode($result);
  } catch (Exception $e) {
      echo 'Exception when calling SuppressionApi->count: ', $e->getMessage(), PHP_EOL;
  }