PHP code example of postalsys / emailengine-php

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

    

postalsys / emailengine-php example snippets


use EmailEnginePhp\EmailEngine;

$ee = new EmailEngine(array(
    "access_token" => "3eb50ef80efb67885afb43844df8ae01e4eecb99c4defac3aa37ec5b8b4f1339",
    "service_secret" => "a23da152f5b88543f52420a0de0e0eb6",
    "ee_base_url" => "http://127.0.0.1:3000/",
    "redirect_url" => "http://127.0.0.1:5000/handler.php",
));

$auth_url = $ee->get_authentication_url(array("account" => null));
header('Location: ' . $auth_url);

$webhook_settings = $ee->get_webhook_settings();
echo "Webhooks are " . ($webhook_settings["enabled"] ? "enabled" : "disabled") . "\n";
echo "Webhooks URL is " . $webhook_settings["url"] . "\n";

$ee->set_webhook_settings(array(
    // are webhooks enabled or not
    "enabled" => true,
    // The URL webhooks are POSTed to
    "url" => "http://127.0.0.1:5000/webhooks.php",
    // Webhooks events to listen for, "*" means all events
    "events" => array("*"),
    // Additional message headers to 

$response = $ee->request($method, $path, $payload = false);

// Register a new account
$account_response = $ee->request('post', '/v1/account', array(
    'account' => "example", // or null if you want it to be autogenerated by EmailEngine
    'name' => 'Andris Reinman',
    'email' => '[email protected]',
    'imap' => array(
        'auth' => array(
            'user' => 'andris',
            'pass' => 'secretvalue',
        ),
        'host' => 'turvaline.ekiri.ee',
        'port' => 993,
        'secure' => true,
    ),
    'smtp' => array(
        'auth' => array(
            'user' => 'andris',
            'pass' => 'secretvalue',
        ),
        'host' => 'turvaline.ekiri.ee',
        'port' => 465,
        'secure' => true,
    ),
));

$account_id = "example";
$account_connected = false;
while (!$account_connected) {
    sleep(1);
    $account_info = $ee->request('get', "/v1/account/$account_id");
    if ($account_info["state"] == "connected") {
        $account_connected = true;
        echo "Account $account_id is connected\n";
    } else {
        echo "Account $account_id is ${account_info['state']}...\n";
    }
}

$account_id = "example";
$submit_response = $ee->request('post', "/v1/account/$account_id/submit", array(
    "from" => array(
        "name" => "Andris Reinman",
        "address" => "[email protected]",
    ),
    "to" => array(
        array(
            "name" => "Ethereal",
            "address" => "[email protected]",
        ))
    ,
    "subject" => "Test message",
    "text" => "Hello from myself!",
    "html" => "<p>Hello from myself!</p>",
));

$account_id = "example";
$attachment_id = "AAAAAQAABRQ";
$ee->download("/v1/account/$account_id/attachment/$attachment_id");