Skip to main content

Send an email

<?php
$ch = curl_init("https://app.usesendi.com/api/emails");

curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST => true,
    CURLOPT_HTTPHEADER => [
        "Authorization: Bearer snd_your_api_key",
        "Content-Type: application/json"
    ],
    CURLOPT_POSTFIELDS => json_encode([
        "from" => "you@yourdomain.com",
        "to" => ["user@example.com"],
        "subject" => "Hello from Sendi",
        "html" => "<p>It just works.</p>"
    ])
]);

$response = curl_exec($ch);
$data = json_decode($response, true);
echo $data["id"];

curl_close($ch);

With Guzzle

composer require guzzlehttp/guzzle
<?php
use GuzzleHttp\Client;

$client = new Client();

$response = $client->post("https://app.usesendi.com/api/emails", [
    "headers" => [
        "Authorization" => "Bearer snd_your_api_key",
        "Content-Type" => "application/json"
    ],
    "json" => [
        "from" => "you@yourdomain.com",
        "to" => ["user@example.com"],
        "subject" => "Hello from Sendi",
        "html" => "<p>It just works.</p>"
    ]
]);

$data = json_decode($response->getBody(), true);
echo $data["id"];

With Laravel

<?php
use Illuminate\Support\Facades\Http;

$response = Http::withToken('snd_your_api_key')
    ->post('https://app.usesendi.com/api/emails', [
        'from' => 'you@yourdomain.com',
        'to' => ['user@example.com'],
        'subject' => 'Hello from Sendi',
        'html' => '<p>It just works.</p>'
    ]);

$id = $response->json('id');