Overview

Transaction emails are once-off emails to one or more recipients. You can use this request to send emails up to your defined quota.

The Method

API-Method
RESTPOSThttps://[Your URL]/api/2.0/trans_mails
XML-RPCCalltransactional._mails.CreateTransactionalMail

Your method must be structured as follows:

Parameters

PropertyTypeDescription
$headers structarrayAn array of headers to use when sending the email.
$bodystructarrayAn array containing at least a text or an HTML element, defining the body of the email.
$attachmentsstructarrayAn array containing the attachments for the email.
$optionsstructarrayAn array containing sending options to use when sending the mail.

Properties

For each of the parameters listed above, there are a variety of properties you can specify.

ParameterPropertyTypeDescriptionDefaultRequired Example
$headers fromarrayThe ‘From’ email address. If multiple email addresses are found in the array the first one will be used.noneyes$headers[‘from’] = array(‘[email protected]’ => ‘From name’)
reply_toarrayThe ‘Reply-to’ email address. If multiple email addresses are found in the array the first one will be used.noneyes$headers[‘reply_to’] = array(‘[email protected]’ => ‘Reply name’)
toarrayThe email addresses to send to. This field can contain multiple email addresses to send to and a new transaction will be created for each address. (Only when “Keep transactions private” is active on your customer settings.) Multiple email addresses will result in a the transactions queued for batch sending. If the value of the array is an array then this array will be used for personalising the content of the mail.noneyes$headers[‘to’] = array(’[email protected]’ => ‘Email1 name’, ’[email protected]’ => array(‘name’ => ‘Email2 name’, ‘custom_tags’ => ‘custom_value’))
ccarrayThe email addresses to cc the mail to. This field can contain multiple email addresses.noneno$headers[‘cc’] = array(’[email protected]’ => ‘Email1 name’, ’[email protected]’ => ‘Email2 name’)
subjectstringThe subject of the email to be sent.noneyes$headers[‘subject’] = ‘Example subject’
trans-group-namestringThe name of the category to store the transaction under.noneno$headers[‘trans-group-name’] = ‘Statements’
trans-{customfield}stringCustom data to assign to the header of the mail. All custom fields must begin with `trans-`.noneno$headers[‘trans-custom-id’] = ‘Ae4537gi974’
$bodyhtmlstringThe HTML body of the mail to be sent.noneno$body[‘html’] = ‘ … ‘
textstringThe text part of the mail to be sent.noneno$body[‘text’] = ‘Text part’
$attachmentsfilenamestringThe name of the attachment file.noneyes$attachments[][‘filename’] = ‘image.jpg’
database64 encoded stringThe base64_encoded data of the file attachment.noneyes$attachments[][‘data’] = ‘/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAAUDBAQEAwUEBAQF’
content_idstringThe content ID of an embedded image. A matching content ID must be found in the HTML.noneno$attachments[][‘content_id’] = ‘[email protected]
$optionstrack_opensstringWhether to track opens for this transaction.yesno$options[‘track_opens’] = ‘no’
track_linksstringWhether to track the links for this transaction.yesno$options[‘track_links’] = ‘no’
batch_sendstringIf set to ‘yes’ transactions will be queued for sending instead of sending each one immediately.nono$options[‘batch_send’] = ‘yes’
unsubscribe_redirect_urlstringTakes a URL value to redirect to nonenohttps://www.domain.com/

Responses

TypeDescriptionExample
arrayAn array containing transaction the ID.array(‘transaction_id’ => ‘2wBDAAUDBAQEA21234f001’)

Code Samples

This is an example of the JSON for a request.

<?php

$curl = curl_init();

$auth = base64_encode($username . ':' . $apikey);
$headers[] = 'Authorization: Basic ' . $auth;
$headers[] = 'Content-Type: application/json';
curl_setopt_array($curl, array(
  CURLOPT_URL => '(Your Url)/api/2.0/trans_mails',
  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 =>'{
    "headers": {
        "from":[email protected],
        "reply_to":[email protected],
        "to":[email protected],
        "subject":"Test"
    },
    "body": {
        "html":"Example body",
        "text":"Example Text"
    },
    "attachments":[{
        "filename" => "image.jpg",
        "data" => "/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAAUDBAQEAwUEBAQF"
}]
}',
  CURLOPT_HTTPHEADER => $headers
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

This is an simple example of sending a transaction.

$headers = array(
  'to' => array('[email protected]' => 'Email name'),
  'from' => array('[email protected]' => 'From name'),
  'trans-group-name' => 'Custom group',
  'subject' => 'Example subject',
);
$body = array(
  'html' => 'Example body',
  'text' => 'Example Text',
);
$attachments[] = array(
  'filename' => 'image.jpg',
  'data' => '/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAAUDBAQEAwUEBAQF',
);
$options = array();
$result = $api->send($header, $body, $attachments, $options);
$transaction = $api->get($result['transaction_id']);