PHP code example of rapidmail / rapidmail-apiv3-client-php

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

    

rapidmail / rapidmail-apiv3-client-php example snippets




use Rapidmail\ApiClient\Client;

$client = new Client('api_username_hash', 'api_password_hash');

$mailingService = $client->mailings();

// Iterate all mailings 

foreach($mailingService->query() as $mailing) {
    var_dump($mailing);
}

// Filter for sent mailings newer than a given date 

var_dump(
    $mailingService->query([
        'created_since' => '2019-09-01 10:22:00',
        'status' => 'sent'
    ])
);

$listService = $client->recipientlists();

foreach ($listService->query() as $list) {
    var_dump($list);
}

$recipientsService = $client->recipients();

$collection = $recipientsService->query(
    [
        'recipientlist_id' => 123456789 // Recipientlist ID MUST be provided
    ]
);

foreach ($collection as $recipient) {
    var_dump($recipient);
}

$recipientsService = $client->recipients();

var_dump(
    $recipientsService->create(
        // Dataset: Represents the recipient dataset you're creating
        [
            'recipientlist_id' => 123456789, // Required
            'email' => '[email protected]', // Required
            'firstname' => 'John',
            'lastname' => 'Doe',
            'gender' => 'male'
        ],
        // Flags: Configures system behavior, like sending activationmails
        [
            'send_activationmail' => 'yes'
        ]
    )
);

use \Rapidmail\ApiClient\Exception\ApiClientException;

try {
    $mailingService->query(['status' => 'unknown']);
} catch (ApiClientException $e) {
    // Catch API client exceptions
    echo "Exception raised: " . $e->getMessage();
}