PHP code example of inboxroad / inboxroad-php

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

    

inboxroad / inboxroad-php example snippets




// Include Composer autoloader
eed it later:
$httpClient = new Inboxroad\HttpClient\HttpClient((string)getenv('INBOXROAD_API_KEY'));

// Send email, method 1: 
try {

    // Create the message object
    $message = (new Inboxroad\Models\Message())
        ->setFromEmail((string)getenv('INBOXROAD_SEND_EMAIL_FROM_EMAIL'))
        ->setToEmail((string)getenv('INBOXROAD_SEND_EMAIL_TO_EMAIL'))
        ->setToName('Inboxroad API Test')
        ->setReplyToEmail((string)getenv('INBOXROAD_SEND_EMAIL_FROM_EMAIL'))
        ->setSubject('Testing')
        ->setText('Testing...')
        ->setHtml('<strong>Testing...</strong>');
    
    // Create the endpoint connection
    $messages = new Inboxroad\Api\Messages($httpClient);
    
    // Send the message
    $response = $messages->send($message);
    
    // Get the message id
    echo $response->getMessageId() . PHP_EOL;

} catch (\Inboxroad\Exception\RequestException $e) {

  echo $e->getMessage() . PHP_EOL;
}

// Send email, method 2: 
try {

    // Create the object instance
    $inboxroad  = new Inboxroad\Inboxroad($httpClient);
    
    // Access the messages endpoint and send a message
    $response  = $inboxroad->messages()->send([
        'fromEmail'     => (string)getenv('INBOXROAD_SEND_EMAIL_FROM_EMAIL'),
        'toEmail'       => (string)getenv('INBOXROAD_SEND_EMAIL_TO_EMAIL'),
        'toName'        => 'Inboxroad API Test',
        'replyToEmail'  => (string)getenv('INBOXROAD_SEND_EMAIL_FROM_EMAIL'),
        'subject'       => 'Testing',
        'text'          => 'Testing...',
        'html'          => '<strong>Testing...</strong>'
    ]);
    
    // Get the message id
    echo $response->getMessageId() . PHP_EOL;

} catch (\Inboxroad\Exception\RequestException $e) {

    echo $e->getMessage() . PHP_EOL;
}
bash
$ composer