PHP code example of shawnmccool / minimal-php-postmark-sdk
1. Go to this page and download the library: Download shawnmccool/minimal-php-postmark-sdk 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/ */
shawnmccool / minimal-php-postmark-sdk example snippets
use MinimalPhpPostmarkSdk\{Mailing, Email};
new Mailing(
'from name',
Email::fromString('[email protected]'),
Email::fromString('[email protected]'),
'subject line',
'email body'
);
use MinimalPhpPostmarkSdk\{Mailing, Email};
new Mailing(
'from name',
Email::fromString('[email protected]'),
Email::fromString('[email protected]'),
'subject line',
'email body',
[],
'holiday-sales-campaign',
[
'user_id' => 1,
'description' => 'this information may be maximum 80 characters'
]
);
use MinimalPhpPostmarkSdk\{Mailing, Email, Attachment};
new Mailing(
'from name',
Email::fromString('[email protected]'),
Email::fromString('[email protected]'),
'subject line',
'email body',
[
new Attachment(
'filename.pdf',
'application/pdf',
file_get_contents('local.pdf')
)
]
);
use MinimalPhpPostmarkSdk\{Mailing, Email};
new Mailing(
'from name',
Email::fromString('[email protected]'),
Email::fromString('[email protected]'),
null, null, [], '', [],
'postmark template alias'
);
use MinimalPhpPostmarkSdk\{Mailing, Email};
new Mailing(
'from name',
Email::fromString('[email protected]'),
Email::fromString('[email protected]'),
null, null, [], '', [], '',
'template id'
);
use MinimalPhpPostmarkSdk\{Mailing, Email};
new Mailing(
'from name',
Email::fromString('[email protected]'),
Email::fromString('[email protected]'),
null, null, [], '', [], '',
'template id',
[
'customer_name' => 'Roger',
'product_name' => 'A really fun gift.'
]
);
use MinimalPhpPostmarkSdk\{Mailing, Email};
new Mailing(
fromName: 'from name',
fromEmail: Email::fromString('[email protected]'),
toEmail: Email::fromString('[email protected]'),
templateId: 'template id',
templateModel: [
'customer_name' => 'Roger',
'product_name' => 'A really fun gift.'
]
);
use MinimalPhpPostmarkSdk\PostmarkApi;
$postmark = new PostmarkApi('server token');
use MinimalPhpPostmarkSdk\{ErrorResponse,PostmarkApi,Mailing,Email,SuccessResponse};
$mailing = new Mailing(
'from name',
Email::fromString('[email protected]'),
Email::fromString('[email protected]'),
null, null, [], '', [], '',
'template id'
);
$response = (new PostmarkApi('server token'))->single($mailing);
echo match (get_class($response)) {
SuccessResponse::class => "Successfully sent message {$response->messageId()}.",
ErrorResponse::class => "Could not send message. {$response->errorMessage()}",
};
use MinimalPhpPostmarkSdk\{PostmarkApi,Mailing,Email};
$mailings = [
new Mailing(
'from name',
Email::fromString('[email protected]'),
Email::fromString('[email protected]'),
null, null, [], '', [], '',
'template id'
),
new Mailing(
'from name',
Email::fromString('[email protected]'),
Email::fromString('[email protected]'),
null, null, [], '', [], '',
'template id'
)
];
# to send a batch with default settings
(new PostmarkApi('server token'))->batch($mailings);
# manually specify chunk size {how many mailings to send in one call)
(new PostmarkApi('server token'))->batch($mailings, 100);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.