PHP code example of cicerbro / sendy-php-api

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

    

cicerbro / sendy-php-api example snippets


composer 

// New way using PSR4 Standard autoloader. Recommended
mended.

// 2. Configuration.
$config = [
	'sendyUrl' => 'https://send_installation_url.com', // Your Sendy installation URL (without trailing slash).
	'apiKey'   => 'XXXXXXXXXXXXXXXX', // Your API key. Available in Sendy Settings.
	'listId'   => 'XXXXXXXXXXXXXXXX',
];

use AhmadAwais\Sendy\API as Sendy;

$sendy = new Sendy( $config );

// Method #1: Subscribe.
$responseArray = $sendy->subscribe(
	[
		'email'     => '[email protected]', // This is the only field ).
		'country'   => 'US', // User 2 letter country code (optional).
		'ipaddress' => 'XX.XX.XX.XXX', // User IP address (optional).
		'referrer'  => 'https://AhmadAwais.com/', // URL where the user signed up from (optional).
		'gdpr'      => true, // GDPR compliant? Set this to "true" (optional).
	]
);

$responseArray = $sendy->unsubscribe( '[email protected]' );

$responseArray = $sendy->subStatus( '[email protected]' );


$responseArray = $sendy->delete( '[email protected]' );


$responseArray = $sendy->subCount();

// Method #6: Campaign — Draft And/Or Send as well.
$responseArray = $sendy->campaign(
	array(
		'from_name'            => 'Your Name',
		'from_email'           => '[email protected]',
		'reply_to'             => '[email protected]',
		'title'                => 'Title', // the title of your campaign.
		'subject'              => 'Your Subject',
		'plain_text'           => 'An Amazing campaign', // Optional.
		'html_text'            => '<h1>Amazing campaign</h1>',
		'brand_id'             => 1, // Required only if you are creating a 'Draft' campaign. That is `send_campaign` set to 0.
		'send_campaign'        => 0, // SET: Draft = 0 and Send = 1 for the campaign.
		// Required only if you set send_campaign to 1 and no `segment_ids` are passed in.. List IDs should be single or comma-separated.
		'list_ids'             => 'XXXXXXXX, XXXXXXXX',
		// Required only if you set send_campaign to 1 and no `list_ids` are passed in. Segment IDs should be single or comma-separated.
		'segment_ids'          => '1',
		// Lists to exclude. List IDs should be single or comma-separated. (optional).
		'exclude_list_ids'     => '',
		// Segments to exclude. Segment IDs should be single or comma-separated. (optional).
		'exclude_segments_ids' => '',
		'query_string'         => 'XXXXXXXX', // Eg. Google Analytics tags.
	)
);

// Method #7: Change the `XXXXXXX` you are referring to at any point.
$sendy->setListId( 'XXXXXXX' );

// Method #7: Get the `XXXXXXX` you are referring to at any point.
$sendy->getListId();

    // E.g. SUCCESS response.
    [
        'status'  => true,
        'message' => 'Already Subscribed'
    ];

    // E.g. FAIL response.
    [
        'status'  => false,
        'message' => 'Some fields are missing.'
    ];