PHP / Laravel

Integrasi AyoSend dengan PHP biasa atau Laravel HTTP Client.

Laravel

use Illuminate\Support\Facades\Http;

$response = Http::withToken(env('AYOSEND_API_KEY'))
    ->post('https://api.ayosend.id/v1/emails', [
        'from'    => 'Toko <no-reply@toko.com>',
        'to'      => ['pelanggan@email.com'],
        'subject' => 'Kode OTP kamu',
        'html'    => '<p>Kode OTP: <strong>847291</strong></p>',
    ]);

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

PHP Vanilla

$ch = curl_init('https://api.ayosend.id/v1/emails');
curl_setopt_array($ch, [
    CURLOPT_POST           => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER     => [
        'Authorization: Bearer ' . $_ENV['AYOSEND_API_KEY'],
        'Content-Type: application/json',
    ],
    CURLOPT_POSTFIELDS => json_encode([
        'from'    => 'Toko <no-reply@toko.com>',
        'to'      => ['pelanggan@email.com'],
        'subject' => 'Kode OTP kamu',
        'html'    => '<p>Kode OTP: <strong>847291</strong></p>',
    ]),
]);
$result = json_decode(curl_exec($ch), true);
echo $result['id'];