<?php
use \common\components\UnisenderAPI;
use \yii\helpers\Json;

$email = 'bystrov@kupitsite.ru';



$sender = new UnisenderAPI();
// Create the send list
$newList = $sender->createList();
$newListObject=Json::decode($newList);
if (array_key_exists('result', $newListObject) && array_key_exists('id', $newListObject['result'])) {
    $newListId=$newListObject['result']['id'];
    // Subscribe user to new List
    $sender->subscribe(['list_ids' => $newListId, 'fields' => ['email' => $email]]);
    // Create new message
    $newMessageId=$sender->createEmailMessage('bystrov', $email, 'Testing Subject', 'Testing Body <br><a href="http://www.google.com/">Testing link</a><a href="{{_UnsubscribeUrl}}">Отписаться</a>', $newListId);
    // Create new campaign
    $newCampaign = $sender->createCampaign($newMessageId);
}

echo 'Рассылка: '.((isset($newCampaign)) ? $newCampaign : 'Not found');
echo '<br>';
echo 'Список: '.((isset($newListId)) ? $newListId : 'Not found');
echo '<br>';
echo 'Сообщение: '.((isset($newMessageId)) ? $newMessageId : 'Not found');