mvdnbrk/postmark-inbound
postmark-inbound
Simple API to process Postmark Inbound Webhooks.
Requirements
- PHP 8.2 or higher
Installation
You can install the package via composer:
composer require mvdnbrk/postmark-inbound
Usage
$inbound = new \Mvdnbrk\Postmark\InboundMessage(file_get_contents('php://input'));
$inbound->from->name; // John Doe
$inbound->from->email; // john@example.com
$inbound->from->full; // John Doe <john@example.com>
$inbound->tag;
$inbound->mailboxHash;
$inbound->messageStream; // inbound
$inbound->replyTo;
$inbound->textBody;
$inbound->htmlBody;
$inbound->messageId; // MessageID assigned by Postmark.
$inbound->messageIdFromHeaders; // Message-ID value from headers.
$inbound->strippedTextReply;
$inbound->originalRecipient;
$inbound->originalDate; // Wed, 6 Sep 2017 12:00:00 +0200
$inbound->date; // PostmarkDate::class which is an extension of the DateTime::class
$inbound->date->format('Y-m-d H:i:s') // 2017-09-06 12:00:00
$inbound->date->isUtc // boolean, is the date in the UTC timezone?
$inbound->date->timezone; // +02:00
$inbound->date->inUtcTimezone() // Sets the timezone to UTC.
$inbound->subject; // Subject of the message.
$inbound->isSpam; // boolean, is the message to be considered as spam?
$inbound->spamStatus; // Spam status, defaults to 'No' when not present.
$inbound->spamScore; // float, defaults to 0.0 when not present.
$inbound->to->count() // Recipient count.
$inbound->cc->count()
$inbound->bcc->count()
$inbound->attachments->count() // Attachment count.
$inbound->headers->count() // Header count.
Recipients
$inbound->to->each(function($contact) {
$contact->name;
$contact->email;
$contact->full;
$contact->mailboxHash;
});
$inbound->cc->each(function($contact) {
$contact->name;
...
});
$inbound->bcc->each(function($contact) {
$contact->name;
...
});
Get the first recipient:
$inbound->to->first();
Attachments
$inbound->attachments->each(function($attachment) {
$attachment->name;
$attachment->contentType;
$attachment->contentLength;
$attachment->content(); // Base64 decoded data
});
Get the first attachment:
$inbound->attachments->first();
Get the last attachment:
$inbound->attachments->last();
Headers
The Message-ID in the headers are sometimes keyed with upper ID and sometimes they are in the format of Id.
So if you want to get the Message-ID from a message you can simply use the $inbound->messageIdFromHeaders helper attribute.
Please note that $inbound->messageId will give you the id of the message that was assigned by Postmark.
$inbound->headers->each(function($value, $key) {
...
});
$inbound->headers->get('Message-ID');
$inbound->headers->get('MIME-Version');
$inbound->headers->get('Received-SPF');
$inbound->headers->get('X-Spam-Score');
$inbound->headers->get('X-Spam-Status');
...
Any other field in the payload can be read by its camelCased name, for example $inbound->fromName.
The collections are instances of Illuminate\Support\Collection.
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
Related Packages
A simple PHP package for sending messages to Slack, with a focus on ease of use...
Version History
| Version | Released | PHP | Laravel | License |
|---|---|---|---|---|
| v3.0.0 | ^8.2 | ^12.0 || | MIT | |
| v2.4.0 | ^7.1 || | MIT | ||
| v2.3.10 | ^7.1 | MIT | ||
| v2.3.9 | ^7.1 | MIT | ||
| v2.3.8 | ^7.1 | MIT | ||
| v2.3.7 | ^7.1 | MIT | ||
| v2.3.6 | >=7.1 | MIT | ||
| v2.3.5 | >=7.1 | MIT | ||
| v2.3.4 | >=7.1 | MIT | ||
| v2.3.3 | >=7.1 | MIT | ||
| v2.3.2 | >=7.1 | MIT | ||
| v2.3.1 | >=7.1 | MIT | ||
| v2.3.0 | >=7.1 | MIT | ||
| v2.2.0 | >=7.1 | MIT | ||
| v2.1.1 | >=7.0 | MIT | ||
| v2.1.0 | >=7.0 | MIT | ||
| v2.0.0 | ~5.6| | MIT | ||
| v1.0.5 | ~5.6| | MIT | ||
| v1.0.4 | ~5.6| | MIT | ||
| v1.0.3 | ~5.6| | MIT | ||
| v1.0.2 | ~5.6| | MIT | ||
| v1.0.1 | ~5.6| | MIT | ||
| v1.0.0 | ~5.6| | MIT |