CURL
curl -X POST "https://api-email2.nigeriatradehub.gov.ng/send.php" \
-d "to=recipient@example.com" \
-d "subject=Test Subject" \
-d "body=Test Body" \
-d "fromName=Sender Name" \
-d "fromEmail=sender@example.com" \
-d "secret=xxx"
Php Implementation
<?php
// Prepare data to send to the API
$postData = [
'secret' => 'your_secret_key',
'to' => $_POST['to'],
'subject' => $_POST['subject'],
'body' => $_POST['body'],
'from_name' => $_POST['from_name'],
'from_email' => $_POST['from_email']
];
// Initialize cURL
$ch = curl_init("https://api-email2.nigeriatradehub.gov.ng/send.php");
// Set cURL options
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postData));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Execute cURL request and check for errors
$response = curl_exec($ch);
if ($response === false) {
echo 'Error: ' . curl_error($ch);
} else {
$result = json_decode($response, true);
if ($result['status'] == 'success') {
// Code to be executed if successful
echo 'Success: ' . $result['message'];
} else {
// Code to be executed if failed
echo 'Error: ' . $result['message'];
}
}
// Close cURL session
curl_close($ch);
?>
Javascript Implementation
// Function to send email via API
async function sendEmail(postData) {
try {
// Make API request
const response = await fetch("https://api-email2.nigeriatradehub.gov.ng/send.php", {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: new URLSearchParams(postData).toString()
});
// Parse JSON response
const result = await response.json();
// Check for success
if (result.status === 'success') {
console.log('Success: ' + result.message);
} else {
console.log('Error: ' + result.message);
}
} catch (error) {
console.error('Error: ' + error.message);
}
}
// Update variables from source
const to = "";
const subject = "";
const body = "";
const from_name = "";
const from_email = "";
// Prepare data to send to the API
const postData = {
secret: 'your_secret_key',
to: to,
subject: subject,
body: body,
from_name: from_name,
from_email: from_email
};
// Call the function
sendEmail(postData);