PHP code example of jacobbennett / sendyphp

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

    

jacobbennett / sendyphp example snippets


	


	$config = array(
		'api_key' => 'yourapiKEYHERE', //your API key is available in Settings
		'installation_url' => 'http://updates.mydomain.com',  //Your Sendy installation
		'list_id' => 'your_list_id_goes_here'
	);
	
	$sendy = new \SendyPHP\SendyPHP($config);
	
	//you can change the list_id you are referring to at any point
	$sendy->setListId("a_different_list_id");

	//example of a succesful return value
	array(
		'status'=>true,
		'message'=>'Already Subscribed'
	)
	
	//example of a UNsuccesful return value
	array(
		'status'=>false,
		'message'=>'Some fields are missing.'
	)

	$results = $sendy->subscribe(array(
		'name'=>'Jim',
		'email' => '[email protected]', //this is the only field 

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

	$results = $sendy->substatus('[email protected]');

	$results = $sendy->subcount();

	$results = $sendy->createCampaign(array(
		'from_name' => 'Some Name',
		'from_email' => '[email protected]',
		'reply_to' => '[email protected]',
		'subject' => 'Some Subject',
		'plain_text' => 'Amazing campaign', // (optional).
		'html_text' => '<h1>Amazing campaign</h1>',
		'list_ids' => 'your_list_id', // Required only if you set send_campaign to 1.
		'brand_id' => 0, // Required only if you are creating a 'Draft' campaign.
		'query_string' => 'some', // eg. Google Analytics tags.
		'send_campaign' => 0 // Set to 1 if you want to send the campaign as well and not just create a draft. Default is 0.
	));

	
	//set or switch the list id
	$sendy->setListId('another_list_id');
	
	//get the current list id
	echo $sendy->getListId();


		$config = [
			'api_key' => 'xxx', //your API key is available in Settings
			'installation_url' => 'http://my.sendy.installation.com',  //Your Sendy installation
			'list_id' => 'xxx'// List ID
		];
shell
		php vendor/bin/phpunit src/test/SendyPHPTest.php