Skip to main content

PHP

This example uses PHP cURL.

<?php
$payload = [
"subject" => "Hello from Mailtarget",
"from" => [
"email" => "you@your-verified-domain.com",
"name" => "Your Name",
],
"to" => [
["email" => "recipient@example.com"],
],
"bodyText" => "If you can read this, the integration works.",
];

$ch = curl_init("https://transmission.mailtarget.co/v1/layang/transmissions");
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
"Authorization: Bearer " . getenv("MAILTARGET_API_KEY"),
"Content-Type: application/json",
],
CURLOPT_POSTFIELDS => json_encode($payload),
]);

$response = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

echo $status . PHP_EOL;
echo $response . PHP_EOL;

Handle non-2xx responses with the guidance in Errors and Rate Limits.