Fazland's MailUp Rest Client is an unofficial PHP Rest Client for the Email and SMS GatewayProvider MailUp.
The suggested installation method is via composer:
$ composer require fazland/mailup-rest-clientIt's really simple. First of all, configuration!
The mandatory configuration parameters are:
usernamepasswordclient_idclient_secretThe only optional parameter is cache_dir. If set, the access token are saved in that path.
Just create a Context object passing to the constructor the parameters as an array:
use FazlandMailUpRestClientContext;
$config = [
'username' => 'your_username',
'password' => 'your_password',
'client_id' => 'your_client_id',
'client_secret' => 'your_client_secret',
'cache_dir' => 'path_to_your_cache_dir', // Optional
];
$httpClient = new HttpClientImplementation();
$context = new Context($config, $httpClient);To create a MailingList you can follow this example. Please, refer to the MailUp official API docs for the $params array.
use FazlandMailUpRestClientMailingList;
$email = "[email protected]";
$listName = "list_name";
$params = [
// your params...
];
$list = MailingList::create($context, $listName, $email, $params);You can also obtain all the existing lists in your MailUp account by calling the static method MailingList::getAll():
use FazlandMailUpRestClientMailingList;
$lists = MailingList::getAll($context);Once you have an instance of MailingList, you can do the following operations:
Recipientuse FazlandMailUpRestClientRecipient;
$list->addRecipient(new Recipient('Aragorn', '[email protected]', '3333333333', '+39'));Recipientuse FazlandMailUpRestClientRecipient;
$list->updateRecipient(new Recipient('Aragorn', '[email protected]', '3334444444', '+39'));Recipientuse FazlandMailUpRestClientRecipient;
$list->removeRecipient(new Recipient('Aragorn', '[email protected]', '3333333333', '+39'));Recipient by its email$recipient = $list->findRecipient('[email protected]'); // null returned if current email was not found$groups = $list->getGroups();$countRecipients = $list->countRecipients(); // equal to $list->countRecipients(Recipient::STATUS_SUBSCRIBED);
// OR
$countRecipients = $list->countRecipients(Recipient::STATUS_UNSUBSCRIBED);
// OR
$countRecipients = $list->countRecipients(Recipient::STATUS_PENDING);$recipients = $list->getRecipientsPaginated($pageNumber, $pageSize);Recipient objects:$list->import($recipients);Each MailingList can be split into multiple groups. The operations available are the following:
$group->getName();
$group->setName('Gondor Army');$group->getNotes();
$group->setNotes('10.000 knights and 20.000 peons');$group->isDeletable();
$group->setDeletable(true);$group->delete();use FazlandMailUpRestClientRecipient;
$legolas = new Recipient('Legolas Thranduilion', '[email protected]', '3334444444', '+39');
$group->addRecipient($legolas);
$group->removeRecipient($legolas);
$lothlorienCitizens = $group->getRecipients();Contributions are welcome. Feel free to open a PR or file an issue here on GitHub!
MailUp Rest Client is licensed under the MIT License - see the LICENSE file for details