PHP code example of knplabs / mailjet-api-php

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

    

knplabs / mailjet-api-php example snippets




// This file is generated by Composer
uest/User;

$user = new User(new Client('api_key', 'secret_key'));
$userInfo = $user->getInfo();

var_dump($userInfo);

//(
//    [username] => KnpLabs
//    [email] => [email protected]
//    [locale] => en_US
//    [currency] => USD
//    [timezone] => America/New_York
//    [firstname] => KnpLabs
//    ....
//)



// This file is generated by Composer
uestApi;

$client = new Client('api_key', 'secret_key');
$userInfo = $client->get(RequestApi::USER_INFOS);

var_dump($userInfo);

//(
//    [username] => KnpLabs
//    [email] => [email protected]
//    [locale] => en_US
//    [currency] => USD
//    [timezone] => America/New_York
//    [firstname] => KnpLabs
//    [lastname] =>
//    [company_name] => KnpLabs
//    [contact_phone] =>
//    [address_street] =>
//    [address_postal_code] =>
//    [address_city] =>
//    [address_country] =>
//    [tracking_openers] => 1
//    [tracking_clicks] => 1
//)



// ... initialize client

$result = $client->post(RequestApi::USER_DOMAIN_ADD, array(
    'domain' => 'example.com'
));

var_dump($result);

//(
//    [status]    => 200
//    [file_name] => empty_file
//    [id]        => 123
//)



use Mailjet/Event/EventFactory;

$factory = new EventFactory();

// fetch incoming data into $data array, example
//(
//    [event]          => open
//    [email]          => [email protected]
//    [mj_contact_id]  => 123
//    [mj_campaign_id] => 123
//    [customcampaign] => Hello from KnpLabs
//    [ip]             => 127.0.0.1
//    [geo]            => US
//    [agent]          => Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:21.0) Gecko/20100101 Firefox/21.0
//)

$event = $factory->createEvent($data);

echo get_class($event); // \Mailjet\Event\Events\OpenEvent
echo $event->getType(); // open
echo $event->getIp();   // 127.0.0.1



$this->container->get('knp_mailjet.api');



$this->container->get('knp_mailjet.api.request.user')->getInfo();
bash
$ php composer.phar 
json
{
    "nplabs/mailjet-api-php": "1.*"
    }
}
bash
$ php composer.phar install

php composer.phar install --dev