PHP code example of parcelwing / parcelwing-php
1. Go to this page and download the library: Download parcelwing/parcelwing-php 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/ */
parcelwing / parcelwing-php example snippets
arcelWing\ParcelWing;
use ParcelWing\Exceptions\ParcelWingException;
$parcelwing = new ParcelWing($_ENV['PARCELWING_API_KEY']);
try {
$emails = $parcelwing->emails->send([
'from' => 'Acme <[email protected] >',
'to' => '[email protected] ',
'subject' => 'Hello from Parcel Wing',
'html' => '<strong>It works!</strong>',
]);
print_r($emails);
} catch (ParcelWingException $error) {
echo $error->getMessage() . PHP_EOL;
}
$parcelwing = new ParcelWing(
apiKey: $_ENV['PARCELWING_API_KEY'],
baseUrl: 'https://parcelwing.com',
timeoutMs: 30000,
headers: [
'X-Request-Source' => 'my-app',
],
);
$parcelwing->emails->send([
'from' => 'Sender <[email protected] >',
'to' => ['[email protected] ', '[email protected] '],
'subject' => 'Quarterly update',
'text' => 'Plain-text fallback',
'html' => '<p>HTML body</p>',
'reply_to' => '[email protected] ',
'tags' => [
'campaign' => 'q1-update',
],
]);
$parcelwing->emails->send([
'from' => 'Acme <[email protected] >',
'to' => '[email protected] ',
'template_alias' => 'welcome',
'template_params' => [
'first_name' => 'Ada',
'workspace_name' => 'Acme',
],
]);
$contact = $parcelwing->contacts->create([
'email' => '[email protected] ',
'first_name' => 'Ada',
'last_name' => 'Lovelace',
'attributes' => [
'plan' => 'flight',
],
]);
$contacts = $parcelwing->contacts->list([
'limit' => 25,
'status' => 'active',
]);
$updated = $parcelwing->contacts->update($contact['id'], [
'first_name' => 'Augusta Ada',
]);
$parcelwing->contacts->delete($contact['id']);
$result = $parcelwing->contacts->create([
['email' => '[email protected] '],
['email' => '[email protected] '],
]);
$segment = $parcelwing->segments->create([
'name' => 'Flight customers',
'filter_criteria' => [
'version' => 1,
'match' => 'all',
'conditions' => [[
'field' => 'attribute',
'attribute_key' => 'plan',
'operator' => 'equals',
'value' => 'flight',
]],
],
]);
$segments = $parcelwing->segments->list(['
$topic = $parcelwing->topics->create([
'name' => 'Product updates',
'description' => 'News and product announcements.',
'default_subscription' => 'opt_out',
'visibility' => 'public',
]);
$event = $parcelwing->automations->track([
'event_name' => 'user.signup',
'contact_id' => 'contact_id_here',
'payload' => [
'plan' => 'launch',
],
]);
try {
$parcelwing->emails->send([
'from' => 'bad',
'to' => 'not-an-email',
]);
} catch (ParcelWingException $error) {
echo $error->status; // HTTP status, or 0 for network errors
echo $error->type; // validation_error, authentication_error, api_error, etc.
echo $error->errorCode ?? ''; // Parcel Wing error code when available
print_r($error->details);
}
bash
composer