1. Go to this page and download the library: Download couryo/couryo-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/ */
// Creates the contact or merges the attributes of the existing one (same email).
$couryo->contacts->create(['email' => '[email protected]', 'attributes' => ['plan' => 'pro'], 'tags' => ['customer']]);
// A contact event: ends conversions and enrolls the contact in the active sequences with this trigger.
$couryo->events->track(
['contact' => ['email' => '[email protected]'], 'name' => 'order.paid', 'properties' => ['total' => 199.9]],
['idempotency_key' => 'order-1042-paid'],
);
// A campaign for a segment: check it, then send or schedule it.
$campaign = $couryo->campaigns->create([
'name' => 'October news',
'audience' => ['type' => 'segment', 'match' => 'all', 'conditions' => [['field' => 'tag', 'op' => 'eq', 'value' => 'customer']]],
'from' => 'Shop <[email protected]>',
'subject' => 'What is new in October',
'html' => '<p>Hi!</p>',
]);
$check = $couryo->campaigns->preflight($campaign['id']);
if ($check['can_send']) {
$couryo->campaigns->schedule($campaign['id'], new DateTimeImmutable('2026-10-20 09:00', new DateTimeZone('America/New_York')));
}
use Couryo\Exception\WebhookVerificationError;
use Couryo\Webhook;
try {
$event = Webhook::verify(getenv('COURYO_WEBHOOK_SECRET'), $_SERVER, file_get_contents('php://input'));
} catch (WebhookVerificationError $e) {
http_response_code(400);
exit;
}
if ($event['type'] === 'bounced') {
// $event['data']['email_id'], $event['data']['recipient'], $event['data']['explanation']...
}
http_response_code(200);
use Couryo\Exception\WebhookVerificationError;
use Couryo\Webhook;
use Illuminate\Http\Request;
Route::post('/webhooks/couryo', function (Request $request) {
try {
$event = Webhook::verify(config('couryo.webhook_secret'), $request->headers->all(), $request->getContent());
} catch (WebhookVerificationError $e) {
abort(400);
}
if ($event['type'] === 'bounced') {
// ...
}
return response()->noContent();
});
'couryo' => [
'transport' => 'couryo',
],
use Illuminate\Support\Facades\Mail;
$sent = Mail::to($user)->send(new OrderShipped($order));
$sent?->getMessageId(); // msg_... (also in the X-Couryo-Email-ID header of the message)
use Couryo\Couryo;
use Couryo\Http\Psr18Transport;
$factory = new GuzzleHttp\Psr7\HttpFactory(); // any PSR-17 request and stream factory
$couryo = new Couryo([
'api_key' => getenv('COURYO_API_KEY'),
'transport' => new Psr18Transport(new GuzzleHttp\Client(['timeout' => 30]), $factory, $factory),
]);