In order to proceed with the following code, you are required to have SOAP Client Extension enabled in order to continue.
Please use phpinfo() to check if the SOAP Client is allow as shown in below,
If the above required steps are completed, then you would be able to use the Examples provided below to call the API to send out Emails.
try {
// Create the SoapClient first with the API Link including the wsdl.
$client = new SoapClient("https://api.enginemailer.com/SoapAPI/submission.asmx?wsdl");
// Use http://tempuri.org as the Namespace
$ns = 'http://tempuri.org/';
// Enter the UserID in $User that is found in the Profile Page
$User = 'UserID from Profile Page';
// Add the UserID into the Parameters that will be put
//into the Authentication Header
$headerBody = array('User' => $User);
// Create the JSON Object with the Parameters, CampaignName,
// ToEmail, Subject, SenderEmail, SubmittedContent(Email Body) and SenderName
// 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";
// 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.pdf";
// Base64 encoded content of the attachment
$base64string = "SG93IHRvIGRlYnVnIFNRTCBTdG9yZWQgUHJvY2VkdXJlDQoNCjEuIExvY2FsIG9ubHkgLSBBenVyZSAoTm8pDQoyLiBQdXQgYnJlYWtwb2ludCBhdCBFWEVDIHN0YXRlbWVudA0KMy4gQ2xpY2sgRGVidWcNCjQuIE9uY2UgaGl0IGJyZWFrcG9pbnQsIHByZXNzIEYxMSB0byBzdGVwIGludG8gdGhlIHN0b3JlZCBwcm9jZWR1cmUu";
$ AttachmentObject ->Content = $base64string;
// 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 because the Parameters
// to sent over to the API would requires String
$jsonEncoded = json_encode($jsonObject);
// Create the Header Variable using the Namespace, name of the
// Header and the Contents in the Header
$header = new SoapHeader($ns, 'AuthHeader', $headerBody);
// Set the Header of the SoapClient specified earlier using the Header defined.
$client->__setSoapHeaders($header);
// Create the Parameter List to include into the SOAP API Call
$params = array('jsonFile' => $jsonEncoded);
// Call the SOAP API and Assign it into $result to check on the
// Results from the API Server.
$result = $client->SendWithJSON($params)->SendWithJSONResult;
}
catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}