composer require quanti/mailq-connector
Add this section to your config. You should use different URL and API key for development and production environment.
There is MailQ object which is facade to whole MailQ REST API. Most common use case is only one company in MailQ per customer. You need to instantiate MailQ object with company ID. Because there are also customers with multiple companies there is MailQFactory which creates MailQ for specific company.
$apiKey = "6e2211bf472a9478f03420fb5897e324c57d05fc27bc0e871083275e98eec344";
$apiUrl = "http://mailq-test.quanti.cz/api/v2";
$mailqFactory = new MailQFactory($apiUrl);
$companyId = 1;
$mailq = $mailqFactory->createMailQ($companyId, $apiKey);
Sandbox is minimum application for playing around with PHP MailQ library.
- Run
docker run --rm -it -v %cd%:/app composer install
to install PHP dependencies - Run
docker run --rm -it -v %cd%:/app php:cli php /app/sandbox/sandbox.php <API key> <company ID>
- Run
docker run --rm -it -v $(pwd):/app composer install
to install PHP dependencies - Run
docker run --rm -it -v $(pwd):/app php:cli php /app/sandbox/sandbox.php <API key> <company ID>
Where API key is your private company key used for authentication and company ID is integer number used for identication company.
$campaigns = $mailq->getCampaigns();
$campaignId = 1;
$campaigns = $mailq->getCampaign();
$company = $mailq->getCompany();
Use this with caution! After regenerating API key application will throw errors because you have already create connection
$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" => "newsletter@example.org",
"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" => "newsletter@example.org",
"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" => "newsletter@example.org",
"replyToEmail" : "newsletter@example.org",
"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 = "test@example.org";
$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" => "notification@example.org"
];
$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" => "notification@example.org"
];
$notification = new \MailQ\Entities\v2\NotificationEntity($data);
$mailq->updateNotification($notification);
$notifications = $mailq->getNotifications();
$notificationId = 1;
$mailq->deleteNotification($notificationId);
In data section are all values which will be used in notification. Keys of associative array are variable names and values are values.
$data = [
"recipientEmail" => "recipient@example.org",
"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 = "recipiet@example.org";
$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);
You can specify e-mail and API returns only recipients list which contains this e-mail
$email = "recipient@example.org";
$recipientsLists = $mailq->getRecipientsLists($email);
$recipientsListId = 1;
$recipients = $mailq->getRecipients($recipientsListId);
$data = [
"recipients" => [
[
"email" => "recipient@example.org",
"data" => [
"key1" => "value1",
"key2" => "value2"
]
]
]
];
$recipients = new \MailQ\Entities\v2\RecipientsEntity($data);
$recipientsListId = 1;
$validate = false;
$mailq->addRecipients($recipients,$recipientsListId,$validate);
$data = [
"email" => "recipient@example.org",
"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 = "recipient@example.org";
$mailq->addRecipientListUnsubscriber($emails,$recipientsListId);
$data = [
"emails" => [
[
"email" => "recipient@example.org"
],
[
"email" => "recipient2@example.org"
]
]
];
$recipientsListId = 1;
$emails = new \MailQ\Entities\v2\EmailAddressesEntity($data);
$mailq->addRecipientListUnsubscribers($emails,$recipientsListId);
$recipientsListId = 1;
$email = "recipient@example.org";
$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);