This release is not production ready yet.. use at own risk!
To use the smtpeter api client, the following things are required:
- A Copernica account
- Generate your API Key
You can install the package using composer.
composer require avido/smtpeter-php-api
Initialize the Smtpeter php api client and set your API key:
$client = new \Avido\Smtpeter\Client($apiKey);
Templates list results can be limit with an offset
and limit
variable
$templates = $client->templates->list();
$templatesWithLimit = $client->templates->list($offset, $limit);
$template = $client->template->get($id);
// simple email
$email = new Email([
'templateId' => 1,
'to' => 'receiver@domain.tld',
'data' => ['array' => 'of replacement vars']
]);
// email with bcc
$email = new Email([
'templateId' => 1,
'to' => 'receiver@domain.tld',
'bcc' => 'bcc@domain.tld',
'data' => ['array' => 'of replacement vars']
]);
// email with replyTo address
$email = new Email([
'templateId' => 1,
'to' => 'receiver@domain.tld',
'replyTo' => 'replyTo@domain.tld',
'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] => recipient@domain.tld
...
)
)
)
For more examples see tests
folder