PHP code example of jeffersongoncalves / laravel-postmark
1. Go to this page and download the library: Download jeffersongoncalves/laravel-postmark 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/ */
jeffersongoncalves / laravel-postmark example snippets
// config/postmark.php
return [
'api_url' => env('POSTMARK_API_URL', 'https://api.postmarkapp.com'),
'token' => env('POSTMARK_TOKEN', ''),
'message_stream' => env('POSTMARK_MESSAGE_STREAM', 'outbound'),
'default_count' => env('POSTMARK_DEFAULT_COUNT', 50),
];
use JeffersonGoncalves\Postmark\Facades\Postmark;
Postmark::sendEmail(
from: '[email protected] ',
to: '[email protected] ',
subject: 'Welcome aboard',
htmlBody: '<p>Hello!</p>',
);
// Several recipients (Postmark accepts up to 50 per message):
Postmark::sendEmail('[email protected] ', ['[email protected] ', '[email protected] '], 'Hi', textBody: 'Hi');
// Any other Postmark field goes in $options:
Postmark::sendEmail(
from: '[email protected] ',
to: '[email protected] ',
subject: 'Welcome aboard',
htmlBody: '<p>Hello!</p>',
options: [
'Cc' => '[email protected] ',
'ReplyTo' => '[email protected] ',
'Tag' => 'welcome',
'TrackOpens' => true,
'TrackLinks' => 'HtmlAndText',
'MessageStream' => 'broadcast',
],
);
Postmark::sendEmailWithTemplate('[email protected] ', '[email protected] ', 'welcome', [
'name' => 'Ada',
'product_url' => 'https://example.com',
]);
Postmark::sendEmailWithTemplate('[email protected] ', '[email protected] ', 1234567);
Postmark::sendBatch([
['From' => '[email protected] ', 'To' => '[email protected] ', 'Subject' => 'Hi', 'TextBody' => 'Hi'],
['From' => '[email protected] ', 'To' => '[email protected] ', 'Subject' => 'Hi', 'TextBody' => 'Hi'],
]);
Postmark::sendBatchWithTemplates([
['From' => '[email protected] ', 'To' => '[email protected] ', 'TemplateAlias' => 'welcome', 'TemplateModel' => ['name' => 'Ada']],
]);
Postmark::templates()->list();
Postmark::templates()->list(count: 10, offset: 0, type: 'Standard');
Postmark::templates()->get('welcome');
Postmark::templates()->create('Welcome', 'Welcome aboard', [
'Alias' => 'welcome',
'HtmlBody' => '<p>Hello {{name}}</p>',
'TextBody' => 'Hello {{name}}',
]);
Postmark::templates()->update('welcome', ['Subject' => 'Welcome!']);
Postmark::templates()->delete('welcome');
Postmark::bounces()->list(['type' => 'HardBounce', 'inactive' => true]);
Postmark::bounces()->get(692560173);
Postmark::bounces()->dump(692560173); // raw bounce source
Postmark::bounces()->activate(692560173); // reactivate the address
Postmark::bounces()->deliveryStats();
Postmark::messages()->outbound(['tag' => 'welcome', 'status' => 'sent']);
Postmark::messages()->inbound(['recipient' => '[email protected] ']);
Postmark::messages()->get('0a129aee-e1cd-480d-b08d-4f48548ff48d');
Postmark::messages()->inboundDetails('e2ecbbfc-fe12-463d-b933-9fe22915106d');
Postmark::stats()->overview();
Postmark::stats()->sends(tag: 'welcome', fromDate: '2026-01-01', toDate: '2026-01-31');
Postmark::stats()->bounces();
Postmark::stats()->opens();
Postmark::stats()->clicks();
Postmark::stats()->spam();
Postmark::server();
Postmark::suppressions()->list(); // configured stream
Postmark::suppressions()->list('broadcast');
Postmark::suppressions()->create('[email protected] ');
Postmark::suppressions()->create(['[email protected] ', '[email protected] '], 'broadcast');
Postmark::suppressions()->delete('[email protected] ');
use JeffersonGoncalves\Postmark\Exceptions\PostmarkException;
try {
Postmark::sendEmail('[email protected] ', '[email protected] ', 'Hi', textBody: 'Hi');
} catch (PostmarkException $e) {
$e->getMessage(); // Postmark's "Message"
$e->getCode(); // Postmark's "ErrorCode", or the HTTP status when absent
$e->errorBody(); // the full decoded error body
}
bash
php artisan vendor:publish --tag=postmark-config