try {
// Set the REST API URL
$restURL = "https://api.enginemailer.com/RESTAPI/Submission/SendEmail";
// Initiate the cURL Method with the REST API URL Specified Previously.
$client = curl_init($restURL);
// Declare the SubstitutionObject first to be used as Dynamic Variables, if there are none then this is not needed.
// Dynamic Variables to be Replaced
$SubstitutionObject->Key = "Dynamic Variables";
// Dynamic Value to Replace
$SubstitutionObject->Value = "Dynamic Value";
// Declare the AttachmentObject first to be used as Attachments, if there are none then this is not needed.
// File name
$AttachmentObject->Filename = "Test.docx";
// Base64 encoded content of the attachment
$base64string = "SG93IHRvIGRlYnVnIFNRTCBTdG9yZWQgUHJvY2VkdXJlDQoNCjEuIExvY2FsIG9ubHkgLSBBenVyZSAoTm8pDQoyLiBQdXQgYnJlYWtwb2ludCBhdCBFWEVDIHN0YXRlbWVudA0KMy4gQ2xpY2sgRGVidWcNCjQuIE9uY2UgaGl0IGJyZWFrcG9pbnQsIHByZXNzIEYxMSB0byBzdGVwIGludG8gdGhlIHN0b3JlZCBwcm9jZWR1cmUu";
$ AttachmentObject ->Content = $base64string;
// Create the JSON Object with the UserKey, Parameters, CampaignName, ToEmail, Subject, SenderEmail, SubmittedContent(Email Body), SenderName and SubstitutionTags
// Enter the UserID in $User that is found in the Profile Page
$jsonObject->UserKey = "UserID from Profile Page";
// Campaign Name
$jsonObject->CampaignName = "Campaign Name";
// Email Address to send to
$jsonObject->ToEmail = "Email To Send To";
// Subject of the Email
$jsonObject->Subject = "Subject of the Email";
// Sender's Email, please take note that the Domain of the Sender's
// Email have to be the same as the Domain Specified in the Portal.
$jsonObject->SenderEmail = "Sender's Email";
// Content of the Email
$jsonObject->SubmittedContent = "Email Body";
// Name of the Sender
$jsonObject->SenderName = "Sender's Name";
// Leave Empty with array() if there are no Dynamic Variables.
$jsonObject->SubstitutionTags = array($SubstitutionObject);
// Leave Empty with array() if there are no Attachments.
$jsonObject->Attachments = array($AttachmentObject);
// Encode the Json Object into a String
$jsonEncoded = json_encode($jsonObject);
// Return the Transfer as String
curl_setopt($client, CURLOPT_RETURNTRANSFER, true);
// Use POST Method
curl_setopt($client, CURLOPT_POST, true);
// The Post Parameters that we will be Passing
curl_setopt($client, CURLOPT_POSTFIELDS, $jsonEncoded);
// Calls the Rest API
$curl_response = curl_exec($client);
curl_close($client);
}
catch (Exception $e)
{
echo 'Caught exception: ', $e->getMessage(), "\n";
}