1. Go to this page and download the library: Download richardhj/epost-api 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/ */
// Create letter and envelope
$letter = new Richardhj\EPost\Api\Letter();
$envelope = new Richardhj\EPost\Api\Metadata\Envelope();
$envelope
->setSystemMessageTypeNormal() // For sending an electronic letter *OR*
->setSystemMessageTypeHybrid() // For sending a physical letter
->setSubject('Example letter');
// Add recipients for normal letter
$recipient = new Richardhj\EPost\Api\Metadata\Envelope\Recipient\Normal::createFromFriendlyEmail('John Doe <[email protected]>');
$envelope->addRecipientNormal($recipient);
// Set recipients and delivery options for printed letter
$recipient = new Richardhj\EPost\Api\Metadata\Envelope\Recipient\Hybrid();
$recipient
->setFirstName('John')
->setLastName('Doe')
->setStreetName('…')
->setZipCode('1234')
->setCity('…');
$envelope->addRecipientPrinted($recipient);
// Set delivery options
$deliveryOptions = new Richardhj\EPost\Api\Metadata\DeliveryOptions();
$deliveryOptions
->setRegisteredStandard() // This will make the letter sent as "Einschreiben ohne Optionen"
->setColorColored() // To make it expensive
->setCoverLetterIncluded(); // The cover letter (with recipient address block) is
// Prepare letter
$letter
->setTestEnvironment(true)
->setAccessToken($token)
->setEnvelope($envelope)
->setCoverLetter('This is an example');
// Set attachments
$letter->addAttachment('/var/www/test.pdf');
// Create and send letter
try {
$letter
->create()
->send();
} catch (GuzzleHttp\Exception\ClientException $e) {
$errorInformation = \GuzzleHttp\json_decode($e->getResponse()->getBody());
}