PHP code example of avido / smtpeter-php-api

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

    

avido / smtpeter-php-api example snippets


$client = new \Avido\Smtpeter\Client($apiKey);

$templates = $client->templates->list();
$templatesWithLimit = $client->templates->list($offset, $limit);

$template = $client->template->get($id);

// simple email
$email = new Email([
    'templateId' => 1,
    'to' => '[email protected]',
    'data' => ['array' => 'of replacement vars']
]);
// email with bcc
$email = new Email([
    'templateId' => 1,
    'to' => '[email protected]',
    'bcc' => '[email protected]',
    'data' => ['array' => 'of replacement vars']
]);
// email with replyTo address
$email = new Email([
    'templateId' => 1,
    'to' => '[email protected]',
    'replyTo' => '[email protected]',
    'data' => ['array' => 'of replacement vars']
]);

$client->email->send($email);

$messageId = 'abcdef1234';
$client->email->resend($messageId   );

$messageId = 'abcdef1234';
// by default only the html body is retrieved. 
$loadHtml = true;
$loadAttachments = true;
$loadHeaders = true;
$client->email->get($messageId, $loadHtml, $loadAttachments, $loadHeaders);


$messageId = 'abcdef1234';
$events = $client->events->message($messageId);
// optional you can filter by date/ tags
$from = '2022-01-01';
$end = '2022-01-07';
$filterd = $client->events->message($messageId, $from, $end);
print_r($events);
...
Illuminate\Support\Collection Object
(
    [items:protected] => Array
        (
            [0] => Avido\Smtpeter\Resources\Event Object
             (
                [id] => abcdef1234
                [time] => DateTime Object
                    (
                        [date] => 2022-02-01 08:36:01.000000
                        [timezone_type] => 3
                        [timezone] => UTC
                    )
            
                [recipient] => [email protected]
                ...
             )
        )
)

composer