PHP code example of messenger_os / messenger_os-php

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

    

messenger_os / messenger_os-php example snippets



// Uncomment the next line if you're using a dependency loader (such as Composer) (recommended)
// TH TO> with the path to the messengeros-loader.php file
// 


use MessengerOS\MessengerOS\Model\Email;
use MessengerOS\MessengerOS\Service\ApiService;

$apiService = new ApiService(
    getenv('MESSENGER_OS_USER_KEY'),
    getenv('MESSENGER_OS_PROJECT_KEY'),
    getenv('MESSENGER_OS_SEND_URL')
);

/* Build email recipients list */
$emailRecipients[] = (new Email\EmailRecipient())
    ->setEmail("[email protected]");

$email = new Email\Email();
$email
    ->setFromName("John | My Company")
    ->setFromEmail("[email protected]")
    ->setRecipients($emailRecipients)
    ->setSubject("Hi [first_name], this is my subject line from API")
    ->setPreviewLine("My preview line from API")
    ->setDeliveryProvider(getenv('MESSENGER_OS_EMAIL_DELIVERY_PROVIDER_KEY'))
    ->setReplyTo("[email protected]")
    ->setParams([
        ['first_name' => 'Thomas']
    ]);

// Send only Email notifications //
try {
    $response = $apiService->sendEmails($emails);
    print $response . "\n";
} catch (Exception $e) {
    echo 'Caught exception: ',  $e->getMessage(), "\n";
}