Untuk mengintegrasikan Mailtarget ke aplikasi, situs web, atau sistem Anda dengan fungsi email menggunakan PHP itu mudah.
Endpoints
Semua panggilan ke API perlu dimulai dengan URL dasar yang sesuai:
Mailtarget production |
Implementasi
Berikut adalah kode dasar, salin dan tempel perintah PHP di bawah ini ke terminal Anda, Anda dapat menyesuaikan kontennya sesuai kebutuhan Anda
Variable | Descriptions |
API_KEY | API Key in dashboard |
CURLOPT_URL |
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://transmission.mailtarget.co/v1/layang/transmissions',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>'{
"bodyText": "Congratulation, you just sent email with Mailtarget. You are truly awesome!",
"bodyHtml": "<!DOCTYPE html><html lang=\"en\"><head><meta charset=\"UTF-8\"><title>Hello from mailtarget</title></head><body><p>Congratulation, you just sent email with Mailtarget. You are truly awesome!</p></body></html>",
"from": {
"email": "SENDER_EMAIL",
"name": "SENDER_NAME"
},
"subject": "Hello from Mailtarget",
"to": [
{
"email": "RECIPIENT_EMAIL",
"name": "RECIPIENT_NAME"
}
],
"replyTo": [
{
"email": "RECIPIENT_EMAIL",
"name": "RECIPIENT_NAME"
}
],
"cc": [
{
"email": "RECIPIENT_EMAIL",
"name": "RECIPIENT_NAME"
}
],
"bcc": [
{
"email": "RECIPIENT_EMAIL",
"name": "RECIPIENT_NAME"
}
],
"headers": [
{
"name": "",
"value": ""
}
],
"attachments": [
{
"mimeType": "image/png",
"filename": "FILE_NAME.png",
"value": "BASE64_ENCODED_CONTENT"
}
],
"metadata": {
"key1": "value1",
"key2": "value2",
},
"templateId":"TEMPLATE_ID"
}',
CURLOPT_HTTPHEADER => array(
'accept: application/json',
'Content-Type: application/json',
'Authorization: Bearer API_KEY'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
Catatan :
API_KEY → ganti dengan API Key
SENDER_EMAIL → ganti dengan sender email
SENDER_NAME → ganti dengan change with sender name
RECIPIENT_EMAIL → ganti dengan recipient email
RECIPIENT_NAME → ganti dengan recipient name
TEMPLATE_ID → ganti dengan template ID