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



// Import PHPMailer classes into the global namespace
use PHPMailer\\PHPMailer\\PHPMailer;
use PHPMailer\\PHPMailer\\SMTP;
use PHPMailer\\PHPMailer\\Exception;

// Load Composer's autoloader
    // Send using SMTP
$mail->Host       = 'smtp.sendpost.io';                     // Set the SMTP server to send through
$mail->SMTPAuth   = true;                                   // Enable SMTP authentication
$mail->Username   = '<username>';                           // SMTP username
$mail->Password   = '<password>';                           // SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;         // Enable implicit TLS encryption
$mail->Port       = 587;                                    // TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`

//Recipients
$mail->setFrom('[email protected]', 'Erlich');
$mail->addAddress('[email protected]', 'Gilfoyle');

//Content
$mail->isHTML(true);                                  //Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

$mail->send();
echo 'Message has been sent';

} catch (Exception $e) {
echo \"Message could not be sent. Mailer Error: {$mail->ErrorInfo}\";
}




 Configure API key authorization: subAccountAuth
$config = sendpost\Configuration::getDefaultConfiguration()->setApiKey('X-SubAccount-ApiKey', 'YOUR_API_KEY');
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
// $config = sendpost\Configuration::getDefaultConfiguration()->setApiKeyPrefix('X-SubAccount-ApiKey', 'Bearer');


$apiInstance = new sendpost\Api\DomainApi(
    // If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
    // This is optional, `GuzzleHttp\Client` will be used as default.
    new GuzzleHttp\Client(),
    $config
);
$create_domain_request = new \sendpost\model\CreateDomainRequest(); // \sendpost\model\CreateDomainRequest

try {
    $result = $apiInstance->createSubAccountDomain($create_domain_request);
    print_r($result);
} catch (Exception $e) {
    echo 'Exception when calling DomainApi->createSubAccountDomain: ', $e->getMessage(), PHP_EOL;
}

json
{
  "repositories": [
    {
      "type": "vcs",
      "url": "https://github.com/sendpost/sendpost-php-sdk.git"
    }
  ],
  "