PHP code example of quanti / mailq-connector

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

    

quanti / mailq-connector example snippets


$apiKey = "6e2211bf472a9478f03420fb5897e324c57d05fc27bc0e871083275e98eec344";
$apiUrl = "http://mailq-test.quanti.cz/api/v2";
$mailqFactory = new MailQFactory($apiUrl);
$companyId = 1;
$mailq = $mailqFactory->createMailQ($companyId, $apiKey);

$campaigns = $mailq->getCampaigns();

$campaignId = 1;
$campaigns = $mailq->getCampaign();

$company = $mailq->getCompany();

$apiKey = $mailq->regenerateApiKey();

$logMessagesEntity = $mailq->getLogMessages();

$logMessageId = 1;
$logMessageEntity = $mailq->getLogMessage($logMessageId);

$data = [
    "name" => "Awesome newsletter",
    "campaign"=> "Spring 2016",
    "subject" => "Buy our new product",
    "senderEmail" => "[email protected]",
    "sendAs" => "Awesome Company",
    "from" => "2018-07-01T00:00:00+00:00",
    "to" => "2018-07-02T00:00:00+00:00",
    "text"=> "TmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciw=",
    "automaticTime"=> false,
    "recipientsListId"=>1,
    "templateUrl" => "http://example.org/newsletter.html",
    "unsubscribeTemplateUrl" => "http://example.org/unsubscribe.html"
];
$newsletter = new \MailQ\Entities\v2\NewsletterEntity($data);
$mailq->createNewsletter($newsletter);
$newsletterId = $newsletter->getId();

$data = [
    "id" => 1,
    "name" => "Awesome newsletter",
    "campaign" => "Spring 2016",
    "subject" => "Buy our new product",
    "senderEmail" => "[email protected]",
    "sendAs" => "Awesome Company",
    "from" => "2018-07-01T00:00:00+00:00",
    "to" => "2018-07-02T00:00:00+00:00",
    "text" => "TmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciw=",
    "automaticTime" => false,
    "recipientsListId" => 1,
    "templateUrl" => "http://example.org/newsletter.html",
    "ampTemplateUrl" => "http://example.org/ampNewsletter.html",
    "unsubscribeTemplateUrl" => "http://example.org/unsubscribe.html"
];
$newsletter = new \MailQ\Entities\v2\NewsletterEntity($data);
$mailq->updateNewsletter($newsletter);
$newsletterId = $newsletter->getId();

$data = [
    "id" => 1,
    "name" => "Awesome newsletter",
    "campaign" => "Spring 2016",
    "subject" => "Buy our new product",
    "senderEmail" => "[email protected]",
    "replyToEmail" : "[email protected]",
    "sendAs" => "Awesome Company",
    "text" => "TmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciwgbmV3c2xldHRlciw=",
    "automaticTime" => false,
    "templateUrl" => "http://example.org/newsletter.html",
    "ampTemplateUrl" => "http://example.org/ampNewsletter.html",
    "unsubscribeTemplateUrl" => "http://example.org/unsubscribe.html"
];
$newsletter = new \MailQ\Entities\v2\NewsletterEntity($data);
$mailq->updateNewsletter($newsletter);
$newsletterId = $newsletter->getId();

$newsletters = $mailq->getNewsletters();

$newsletterId = 1;
$newsletter = $mailq->getNewsletter($newsletterId);

$newsletterId = 1;
$email = "[email protected]";
$mailq->sendTestEmail($email,$newsletterId);

$newsletterId = 1;
$mailq->startNewsletter($newsletterId);

$newsletterId = 1;
$mailq->stopNewsletter($newsletterId);

$data = [
    "name" => "First Notification",
    "code" => "N1",
    "subject" => "{{orderNumber}} order is ready",
    "sendAs" => "Awesome Company",
    "text" => "QWx0ZXJuYXRpdmUgYmFzZTY0IGVtYWlsIHRleHQ=",
    "template" => "QWx0ZXJuYXRpdmUgYmFzZTY0IGVtYWlsIHRleHQ=",
    "ampTemplate" => "QWx0ZXJuYXRpdmUgYmFzZTY0IGVtYWlsIHRleHQ=",
    "appliedSenderEmail" => "[email protected]"
];
$notification = new \MailQ\Entities\v2\NotificationEntity($data);
$mailq->createNotification($notification);
$notificationId = $notification->getId();

$data = [
    "id" => 1,
    "name" => "First Notification",
    "code" => "N1",
    "subject" => "{{orderNumber}} order is ready",
    "sendAs" => "Awesome Company",
    "text" => "QWx0ZXJuYXRpdmUgYmFzZTY0IGVtYWlsIHRleHQ=",
    "template" => "QWx0ZXJuYXRpdmUgYmFzZTY0IGVtYWlsIHRleHQ=",
    "ampTemplate" => "QWx0ZXJuYXRpdmUgYmFzZTY0IGVtYWlsIHRleHQ=",
    "appliedSenderEmail" => "[email protected]"
];
$notification = new \MailQ\Entities\v2\NotificationEntity($data);
$mailq->updateNotification($notification);

$notifications = $mailq->getNotifications();

$notificationId = 1;
$mailq->deleteNotification($notificationId);

$data = [
    "recipientEmail" => "[email protected]",
    "data" => [
        "key1" => "value1",
        "key2" => "value2"
    ],
    "attachments" => [
        [
            "displayName" =>  "Priloha 1",
            "link" => "http://example.org/test.txt",
            "source" => "dGVzdHM=",
            "mimeType" => "text/plain"
        ],
        [
            "displayName" => "Priloha 2",
            "link" => "http://example.org/image.png",
            "source" => "R0lGODlhAQABAIAAAP///////yH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==",
            "mimeType" => "image/png"
        ]
    ]
];
$notificationId = 1;
$notificationData = new \MailQ\Entities\v2\NotificationDataEntity($data);
$mailq->sendNotificationEmail($notificationData,$notificationId);
$notificationDataId = $notificationData->getId();

$notificationId = 1;
$notificationDataId = 2;
$notificationData = $mailq->getNotificationData($notificationId,$notificationDataId);

$notificationId = 1;
$email = "[email protected]";
$notificationsData = $mailq->getNotificationsData($notificationId,$email);

$mailq = $mailqFactory->createMailQ($companyId);
$data = [
    "name" => "All clients",
    "description" => "All clients of our awesome company",
    "variables" => ["salutation","gender"],
    "formVisible" => true
];
$recipientsList = new \MailQ\Entities\v2\RecipientsListEntity($data);
$mailq->createRecipientsList($recipientsList);
$recipientsListId = $recipientsList->getId();

$recipientsListId = 1;
$mailq->deleteRecipientsList($recipientListId);

$recipientsListId = 1;
$recipientsList = $mailq->getRecipientsList($recipientListId);

$email = "[email protected]";
$recipientsLists = $mailq->getRecipientsLists($email);

$recipientsListId = 1;
$recipients = $mailq->getRecipients($recipientsListId);

$data = [
	"recipients" => [
		[
			"email" => "[email protected]",
	        "data" => [
	            "key1" => "value1",
	            "key2" => "value2"
	        ]
		]
	]
];
$recipients = new \MailQ\Entities\v2\RecipientsEntity($data);
$recipientsListId = 1;
$validate = false;
$mailq->addRecipients($recipients,$recipientsListId,$validate);

$data = [
	"email" => "[email protected]",
    "data" => [
        "key1" => "value1",
        "key2" => "value2"
    ]
];
$recipient = new \MailQ\Entities\v2\RecipientEntity($data);
$recipientsListId = 1;
$validate = false;
$mailq->updateRecipient($recipient,$recipientsListId,$validate);

$recipientsListId = 1;
$unsubscribers = $mailq->getRecipientListUnsubscribers($recipientsListId);

$recipientsListId = 1;
$email = "[email protected]";
$mailq->addRecipientListUnsubscriber($emails,$recipientsListId);

$data = [
	"emails" => [
		[
			"email" => "[email protected]"
		],
		[
			"email" => "[email protected]"
		]
	]
];
$recipientsListId = 1;
$emails = new \MailQ\Entities\v2\EmailAddressesEntity($data);
$mailq->addRecipientListUnsubscribers($emails,$recipientsListId);

$recipientsListId = 1;
$email = "[email protected]";
$mailq->deleteRecipientListUnsubscriber($emails,$recipientsListId);

$data = [
	"name" => "SMS notification",
    "code" => "S1",
    "template" => "U01TIHRlc3Qge3t2YXJpYWJsZX19"
];
$smsNotification = new \MailQ\Entities\v2\SmsNotificationEntity($data);
$mailq->createSmsNotification($smsNotification);
$smsNotificationId = $smsNotification->getId();

$data = [
	"name" => "SMS notification",
    "code" => "S1",
    "template" => "U01TIHRlc3Qge3t2YXJpYWJsZX19"
];
$smsNotification = new \MailQ\Entities\v2\SmsNotificationEntity($data);
$mailq->updateSmsNotification($smsNotification);

$smsNotificationId = 1;
$mailq->deleteSmsNotification($smsNotification);

$notifications = $mailq->getSmsNotifications();

$smsNotificationId = 1;
$notifications = $mailq->getSmsNotification($smsNotificationId);

$smsNotificationId = 1;
$data = [
	"toNumber" => "+420123456789",
    "data" => [
        "key1" => "value1",
        "key2" => "value2"
    ]
];
$sms = new \MailQ\Entities\v2\SmsEntity($data);
$mailq->sendSms($sms,$smsNotificationId);
$smsId = $sms->getId();

$smsNotificationId = 1;
$data = [
	"batch" => [
        [    
            "id" => 1,
            "toNumber" => "+420123456789",
            "data" => [         
                "text" => "value1"   
            ]
        ],
        [     
            "id" => 2,
            "toNumber" => "+420123456789",
            "data" => [        
                "text" => "value2"   
            ]
        ]

    ]
];
$smsBatch = new \MailQ\Entities\v2\SmsBatchEntity($data);
$smsBatchResultEntity = $mailq->sendSmsBatch($smsBatch,$smsNotificationId);

$senderEmails = $mailq->getSenderEmails();

$senderEmailId = 1;
$senderEmail = $mailq->getSenderEmail($senderEmailId);

$users = $mailq->getUsers();

$userId = 1;
$user = $mailq->getUser($userId);