PHP code example of oxemis / oximailing

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

    

oxemis / oximailing example snippets



use Oxemis\OxiMailing\OxiMailingClient;

// getenv will allow us to get the OXIMAILING_API_LOGIN/OXIMAILING_API_PWD variables we created before:

$apilogin = getenv('OXIMAILING_API_LOGIN');
$apipwd = getenv('OXIMAILING_API_PWD');

$oximailing = new OxiMailingClient($apilogin, $apipwd);

// or, without using environment variables:

$apilogin = 'your API login';
$apipwd = 'your API password';

$oximailing = new OxiMailingClient($apilogin, $apipwd);


use Oxemis\OxiMailing\OxiMailingClient;

$client = new OxiMailingClient(API_LOGIN,API_PWD);
$user = $client->userAPI->getUser();

echo "Name :" . $user->getCompanyName() . "\n" .
     "Remaining credits : " . $user->getCredits() . "\n";


use Oxemis\OxiMailing\OxiMailingClient;  
use Oxemis\OxiMailing\Objects\Message;

// Create the Client
$apilogin = 'your API login';
$apipwd = 'your API password';
$client = new OxiMailingClient($apilogin, $apipwd);

// Define the message
// TODO : be careful and change the email addresses of the sender and recipients of this example!
$mail = new Message();  
$mail
->addRecipientEmail("[email protected]")
->addRecipientEmail("[email protected]") 
->setSender("[email protected]") 
->setSenderName("Your name") 
->setSubject("Hello world !")
->setHtmlMessage("Hi there ! This is my first email sent with the awesome oximailing-php library !");

// Send the message
$client->sendAPI->send($mail);


use Oxemis\OxiMailing\Objects\Recipient;
use Oxemis\OxiMailing\Objects\Message;
use Oxemis\OxiMailing\OxiMailingClient;

// First of all we need recipients with meta data
$myFirstRecipient = new Recipient();
$myFirstRecipient->setEmail("[email protected]");
$myFirstRecipient->setMetaData(["Name" => "Joe", "ID" => 1]);

$mySecondRecipient = new Recipient();
$mySecondRecipient->setEmail("[email protected]");
$mySecondRecipient->setMetaData(["Name" => "Jane", "ID" => 2]);

// We create the message with {{custom parts}}
// TODO : be careful and change the email addresses of the sender and recipients of this example!
$mail = new Message();  
$mail->addRecipient($myFirstRecipient) 
->addRecipient($mySecondRecipient) 
->setSender("[email protected]") 
->setSenderName("Your name") 
->setSubject("Hello {{Name}} !")
->setHtmlMessage("Hi {{Name}} ! This is your ID : {{ID}}");

// Then we send the two messages in one call !
$client = new OxiMailingClient(API_LOGIN, API_PWD);
$client->sendAPI->send($mail);


use Oxemis\OxiMailing\Objects\Message;

// Define the message
// TODO : be careful and change the email addresses of the sender and recipients of this example!
$mail = new Message();  
$mail
->addRecipientEmail("[email protected]") 
->addRecipientEmail("[email protected]") 
->setSender("[email protected]") 
->setSenderName("Your name") 
->setSubject("Hello world !")
->setHtmlMessage("Hi there ! This is my first email sent with the <a href='https://github.com/oxemis/oximailing-php'>awesome oximailing-php library !</a>")
->setTrackEmails(true);


use Oxemis\OxiMailing\OxiMailingClient;

// Create the client
$client = new OxiMailingClient(API_LOGIN,API_PWD);

// Send the message
$sending = $client->sendAPI->send($mail);

// Store the sending id somewhere
$sid = $sending->getSendingId();


use Oxemis\OxiMailing\Objects\Event;
use Oxemis\OxiMailing\OxiMailingClient;

// Create the client
$client = new OxiMailingClient(API_LOGIN,API_PWD);

// Will return an array of events (or null if none)
// You can filter on many things, here we use the Sending Id
$events = $client->trackingAPI->getEvents(Event::EVENT_TYPE_CLICK, null, null, null, $sid);