avangdev/avang-php

AvangEmail PHP-SDK

dev-master 2020-04-20 17:03 UTC

This package is auto-updated.

Last update: 2024-04-21 01:38:03 UTC


README

A simple AvangEmail library and example for PHP.

Getting started

There are two ways to use AvangEmail PHP SDK:

  1. Installing Via Composer:
composer require --prefer-dist avangdev/avang-php dev-master
  1. Simply download zip

    use example here

Usage

you will need to require vendor/autoload.php file in your index.php

Example: Add new email to mailing lists

<?php
require 'vendor/autoload.php';

$config = new AvangEmailApi_Config(array(
    'publicKey'     => 'PUBLIC-KEY',
    'privateKey'    => 'PRIVATE-KEY',
    'components' => array(
        'cache' => array(
            'class'     => 'AvangEmailApi_Cache_File',
            'filesPath' => dirname(__FILE__) . '/vendor/avangdev/avang-php/AvangEmailApi/Cache/data/cache', // make sure it is writable by webserver
        )

    ),
));
AvangEmailApi_Base::setConfig($config);
date_default_timezone_set('UTC');

$endpoint = new AvangEmailApi_Endpoint_ListSubscribers();
/*===================================================================================*/
// ADD SUBSCRIBER
$response = $endpoint->create('LIST-UNIQUE-ID', array(
    'EMAIL'    => 'john.napi@example.com',
    'FNAME'    => 'John',
    'LNAME'    => 'Napi'
));
// DISPLAY RESPONSE, You can comment bellow
echo '<hr /><pre>';
print_r($response->body);
echo '</pre>';

/*===================================================================================*/
$response = $endpoint->createBulk('LIST-UNIQUE-ID', array(
	array(
		'EMAIL'    => 'john.doe-1@doe.com',
		'FNAME'    => 'John',
		'LNAME'    => 'Doe'
	),
	array(
		'EMAIL'    => 'john.doe-2@doe.com',
		'FNAME'    => 'John',
		'LNAME'    => 'Doe'
	),
	array(
		'EMAIL'    => 'john.doe-3@doe.com',
		'FNAME'    => 'John',
		'LNAME'    => 'Doe'
	)
));
// DISPLAY RESPONSE
echo '<hr /><pre>';
print_r($response->body);
echo '</pre>';

Example: Get all lists


$response = $endpoint->getLists($pageNumber = 1, $perPage = 10);
// DISPLAY RESPONSE
echo '<pre>';
print_r($response->body);
echo '</pre>';
Other Example: see example directory