PHP code example of jiririedl / php-sendy

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

    

jiririedl / php-sendy example snippets


$phpSendyPath = ''; // here you can fill something like 'vendor/SendyPHP' 

$sendy = new \SendyPHP\Sendy('http://mysendyinstalation.mydomain','myAPIKey');

bool subscribe($listID, $email, $name = NULL, array $customFields = array(), &$statusMessage = NULL)

try{
    $sendy = new \SendyPHP\Sendy('http://mysendyinstalation.mydomain','myAPIKey');

    $statusMessage = '';
    $status = $sendy->subscribe('myHashedListID','[email protected]','John Doe',$statusMessage);

    if($status)
        echo "Yeah! New subscriber successfully added";
    else
        echo "Ops! Sendy API responds a problem with adding subscriber - Sendy PHP message :".$statusMessage;

}catch (\SendyPHP\Exception $e)
{
    echo "Ops! An exception raised: ".$e;
}

bool unsubscribe($listID, $email,&$statusMessage = NULL)

try{
    $sendy = new \SendyPHP\Sendy('http://mysendyinstalation.mydomain','myAPIKey');

    $statusMessage = '';
    $status = $sendy->unsubscribe('myHashedListID','[email protected]',$statusMessage);

    if($status)
        echo "Subscriber successfully removed from list";
    else
        echo "Ops! Sendy API responds a problem with unsubscribing - Sendy PHP message :".$statusMessage;

}catch (\SendyPHP\Exception $e)
{
    echo "Ops! An exception raised: ".$e;
}

bool delete($listID, $email,&$statusMessage = NULL)

try{
    $sendy = new \SendyPHP\Sendy('http://mysendyinstalation.mydomain','myAPIKey');

    $statusMessage = '';
    $status = $sendy->delete('myHashedListID','[email protected]',$statusMessage);

    if($status)
        echo "Subscriber successfully deleted from list";
    else
        echo "Ops! Sendy API responds a problem with deleting - Sendy PHP message :".$statusMessage;

}catch (\SendyPHP\Exception $e)
{
    echo "Ops! An exception raised: ".$e;
}

number|false getActiveSubscriberCount($listID, &$statusMessage = NULL)

try{
    $sendy = new \SendyPHP\Sendy('http://mysendyinstalation.mydomain','myAPIKey');

    $statusMessage = '';
    $subscribersCount = $sendy->getActiveSubscriberCount('myHashedListID',$statusMessage);

    if($subscribersCount!==false)
        echo "In this list is $subscribersCount active subscribers";
    else
        echo "Ops! Sendy API responds a problem with getting active subscribers count - Sendy PHP message :".$statusMessage;

}catch (\SendyPHP\Exception $e)
{
    echo "Ops! An exception raised: ".$e;
}

\SendyPHP\Response\SubscriptionStatus getSubscriptionStatus($listID, $email)

try{
    $sendy = new \SendyPHP\Sendy('http://mysendyinstalation.mydomain','myAPIKey');

    $subscriptionStatus = $sendy->getSubscriptionStatus('myHashedListID','[email protected]');

    if($subscriptionStatus->success())
    {
        switch(true)
        {
            case $subscriptionStatus->isSubscribed():
                echo "Subscribed";
                break;
            case $subscriptionStatus->isUnSubscribed():
                echo "Unsubscribed";
                break;
            case $subscriptionStatus->isComplained():
                echo "Complained";
                break;
            case $subscriptionStatus->isUnconfirmed():
                echo "Unconfirmed";
                break;
            case $subscriptionStatus->isHardBounced():
                echo "Hard Bounced";
                break;
            case $subscriptionStatus->isSoftBounced():
                echo "Soft bounced";
                break;
        }
    }
    else
        echo "Ops! Sendy API responds a problem with getting subscribtion status - Sendy PHP message :".$subscriptionStatus->getRawResponse();

}catch (\SendyPHP\Exception $e)
{
    echo "Ops! An exception raised: ".$e;
}

bool createCampaign($brandID, Model\Campaign $campaign, &$statusMessage = NULL)

try{
    $sender = new \SendyPHP\Model\Sender('From name','[email protected]','[email protected]');
    $emailBody = new \SendyPHP\Model\EmailBody('<h1>HTML body of my newsletter</h1>', 'Plaintext body of my newsletter');
    $campaign = new \SendyPHP\Model\Campaign($sender,'My first great newsletter!',$emailBody);
    $brandID = 1; // here fill your brand ID

    $sendy = new \SendyPHP\Sendy('http://mysendyinstalation.mydomain','myAPIKey');

    $statusMessage = '';
    $status = $sendy->createCampaign($brandID,$campaign,$statusMessage);

    if($status)
    {
        echo "Campaign successfully created";
    }
    else
        echo "Ops! Sendy API responds a problem with creating campaign - Sendy PHP message :".$statusMessage;

}catch (\SendyPHP\Exception $e)
{
    echo "Ops! An exception raised: ".$e;
}

bool sendCampaign(array $listIDs, Model\Campaign $campaign, &$statusMessage = NULL)

try{
    $sender = new \SendyPHP\Model\Sender('From name','[email protected]','[email protected]');
    $emailBody = new \SendyPHP\Model\EmailBody('<h1>HTML body of my newsletter</h1>', 'Plaintext body of my newsletter');
    $campaign = new \SendyPHP\Model\Campaign($sender,'My first great newsletter!',$emailBody);
    $listIDs = array(1); // here fill your list IDs

    $sendy = new \SendyPHP\Sendy('http://mysendyinstalation.mydomain','myAPIKey');

    $statusMessage = '';
    $status = $sendy->sendCampaign($listIDs,$campaign,$statusMessage);

    if($status)
    {
        echo "Campaign successfully created and now sending";
    }
    else
        echo "Ops! Sendy API responds a problem with creating and sending campaign - Sendy PHP message :".$statusMessage;

}catch (\SendyPHP\Exception $e)
{
    echo "Ops! An exception raised: ".$e;
}

void setCurlOption($option, $value)

void clearCurlOptions()

void setURL($URL)

void setApiKey($apiKey)