sendMail

Description

This is a helper function that allows you to quickly create and send a campaign.

If you need advanced functions like stats, pausing, resuming etc. consider using functions described inside Campaigns and Mailing Lists sections.

Note that this function shouldn't be used to send transactional emails because our API has a rate limit. In this case, you should use our SMTP server.



Params

NameTypeDescription
apiKeystringAPI key previously generated.
emailsarrayArray with all recipients in the following format:

array( 'name' => 'Name 1', 'email' => '' ),
array( 'name' => 'Name 1', 'email' => '' )

Name is optional and email is required. If an invalid email is provided it will be automatically ignored.
subjectstringSubject of the message.
htmlstringHtml of the message. There is no need to provide plain text as it is automatically generated based on the provided html.
mailboxFromIdintegerId of the mailbox that will be used on the From header. You can get all mailboxes using function.
mailboxReplyIdintegerId of the mailbox that will be used on the Reply-To header. You can get all mailboxes using function.
mailboxReportIdintegerMailbox report id. You can get all mailboxes using function.
packageIdintegerId of the package used to send this email. You can get all packages using function.
attachmentsarrayOptional parameter in case you want to add attachments. Its elements should follow this structure:

array( ‘name’ => ‘Filename.jog’, ‘data’ => ‘DataEncodedInBase64’ )

The data parameter is the content of the file encoded with base64.

 

Returned data

Type: boolean

Description: Return true if emails were corrected placed on mailing list queue.

 

Json sample code

<?php

$curl = curl_init('https://your_address/ccm/admin/api/version/2/&type=json');

// Create rcpt array to send emails to 2 rcpts
$rcpt = array(
    array(
        'name' => 'My Optional Name 1', 
        'email' => 'email1@example.org'
    ), 
    array(
        'name' => null, 
        'email' => 'email2@example.org'
    )
);

$postData = array(
    'function' => 'sendMail',
    'apiKey' => 'apiKey',
    'subject' => 'Subject 1',
	'html' => '<html><head><title>Title</title></head><body><h1>My Email</h1></body></html>',
	'mailboxFromId' => 1,
	'mailboxReplyId' => 1,
	'mailboxReportId' => 1,
	'packageId' => 6,
	'emails' => $rcpt
);

$post = http_build_query($postData);

curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

$json = curl_exec($curl);
if ($json === false) {
    die('Request failed with error: '. curl_error($curl));
}

$result = json_decode($json);
if ($result->status == 0) {
    die('Bad status returned. Error: '. $result->error);
}

var_dump($result->data);

 

Result of API call

bool(true)