PHP code example of leonid74 / sendpulse-php

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

    

leonid74 / sendpulse-php example snippets



ithout Composer (and instead of "c/ApiInterface.php");
// erface.php");
// ("your-path/sendpulse-php/src/Storage/MemcachedStorage.php");
// 
define('API_USER_ID', '');
define('API_SECRET', '');
define('PATH_TO_ATTACH_FILE', __FILE__);

$SPApiClient = new ApiClient(API_USER_ID, API_SECRET, new FileStorage());

// DEBUG level can be mix or one of: DEBUG_NONE (default) or DEBUG_URL, DEBUG_HEADERS, DEBUG_CONTENT
// no debug
$SPApiClient->debugLevel = ApiClient::DEBUG_NONE;
// only URL level debug
$SPApiClient->debugLevel = ApiClient::DEBUG_URL;
// only HEADERS level debug
$SPApiClient->debugLevel = ApiClient::DEBUG_HEADERS;
// max level of debug messages to STDOUT
$SPApiClient->debugLevel = ApiClient::DEBUG_URL | ApiClient::DEBUG_HEADERS | ApiClient::DEBUG_CONTENT;

/*
 * Example: Get Mailing Lists
 */
var_dump($SPApiClient->listAddressBooks());

/*
 * Example: Add new email to mailing lists
 */
 $bookID = 123;
 $emails = array(
    array(
        'email' => '[email protected]',
        'variables' => array(
            'phone' => '+12345678900',
            'name' => 'User Name',
        )
    )
);
 $additionalParams = array(
   'confirmation' => 'force',
   'sender_email' => '[email protected]',
);
 // With confirmation
var_dump($SPApiClient->addEmails($bookID, $emails, $additionalParams));

// Without confirmation
var_dump($SPApiClient->addEmails($bookID, $emails));

/*
 * Example: Send mail using SMTP
 */
$email = array(
    'html' => '<p>Hello!</p>',
    'text' => 'Hello!',
    'subject' => 'Mail subject',
    'from' => array(
        'name' => 'John',
        'email' => '[email protected]',
    ),
    'to' => array(
        array(
            'name' => 'Subscriber Name',
            'email' => '[email protected]',
        ),
    ),
    'bcc' => array(
        array(
            'name' => 'Manager',
            'email' => '[email protected]',
        ),
    ),
    'attachments' => array(
        'file.txt' => file_get_contents(PATH_TO_ATTACH_FILE),
    ),
);
var_dump($SPApiClient->smtpSendMail($email));

/*
 * Example: create new push
 */
$task = array(
    'title' => 'Hello!',
    'body' => 'This is my first push message',
    'website_id' => 1,
    'ttl' => 20,
    'stretch_time' => 0,
);

// This is optional
$additionalParams = array(
    'link' => 'http://yoursite.com',
    'filter_browsers' => 'Chrome,Safari',
    'filter_lang' => 'en',
    'filter' => '{"variable_name":"some","operator":"or","conditions":[{"condition":"likewith","value":"a"},{"condition":"notequal","value":"b"}]}',
);
var_dump($SPApiClient->createPushTask($task, $additionalParams));
bash
composer