How to use Single Send API in PHP Application Form Submission


I need to send order confirmation details and etc email formats to the customer using the transitional email(Single Send API or others). How I need to parse the custom values to the API.

Already created email template too.

It have only for JSON, Can you provide me any document for PHP


Hi @clubstohire,

I'm not particularly familiar with PHP, but no matter what language you use the data sent to the single send API must be properly formatted JSON. Below is some documentation on the built-in JSON methods, but I'm sure there are also a number of libraries that effectively handle JSON data:


Hi Derek,

Thanks for the reply. I created new template on my account and need to send multiple custom values to the api. Can you review below PHP code(whom well know PHP).

$emailId =  "1234567890";
    $to = "";
    $orderNumber = "1234";
    $firstName = "Test";    
    $pickupDate = "25/03/2018";    
    $pickupLocation = "UK";
    $locationSummary = "test";
    $forecast = "test";
    $currentYear = date('Y');
    $emailValues = array(
            'emailId' => $emailId,
            'message' => array(
            'customProperties' => array(
                    'name' => 'ordernumber',
                    'value' => $orderNumber
                'customProperties' => array(
                    'name' => 'firstname',
                    'value' => $firstName
                'customProperties' => array(
                    'name' => 'pickupdate',
                    'value' => $pickupDate
                'customProperties' => array(
                    'name' => 'location',
                    'value' => $pickupLocation
                'customProperties' => array(
                    'name' => 'location_summary',
                    'value' => $locationSummary
                'customProperties' => array(
                    'name' => 'forecast',
                    'value' => $forecast
                'customProperties' => array(
                    'name' => 'current_year',
                    'value' => $currentYear
    $post_json = json_encode($emailValues);
    $hapiKey = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
    $endpoint = "$hapiKey";
    $ch = @curl_init();
    @curl_setopt($ch, CURLOPT_POST, true);
    @curl_setopt($ch, CURLOPT_POSTFIELDS, $post_json);
    @curl_setopt($ch, CURLOPT_URL, $endpoint);
    @curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
    @curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $response = @curl_exec($ch);
    $status_code = @curl_getinfo($ch, CURLINFO_HTTP_CODE);
    $curl_errors = curl_error($ch);
    echo "curl Errors: " . $curl_errors;
        echo "\nStatus code: " . $status_code;
        echo "\nResponse: " . $response;   

I am getting below error:
curl Errors: Protocol " https" not supported or disabled in libcurl Status code: 0 Response:

Please help me to solve the above error or guide me the way to go right direction of my issue


Hi @clubstohire,

That error has a space before the protocol (i.e. " https" instead of "https"). Is it possible that you have an extra space in there somewhere? That error commonly appears when the protocol is mistyped:


Hi @Derek_Gervais,

Please check my code, there is no space in before or after "https" and I tried with "http" also. Same curl execution working for other API, but its not working for the Single Send API. I hope someone will guide me on this, who is well known of PHP.


Hi @clubstohire,

After looking a bit more closely, it looks like the protocol of the URL you specified in $endpoint is http instead of https. That might possibly be the issue, since the HubSpot APIs all require https.


Hi @Derek_Gervais,

Before I tried with https also but now its working. But I am getting below error.

`curl Errors: Status code: 400 Response: {"status":"error","message":"Mismatch in custom properties between template and request.\n - Custom properties in the template, but not in the request: firstname, current_year, location_summary, ordernumber, pickupdate, forecast, location","correlationId":"a21ed56b-7a88-4420-83bd-fcc564dcc3df","sendResult":"MISSING_TEMPLATE_PROPERTIES","requestId":"79f9621e2a0ed45af1e72e411196bf87"}`

But I passed all the values to the API. Please review my above code.


Hi @Derek_Gervais,

I solved the issue and receiving the email also. If any other issues I will posted in Forum.

Thank you for your assistance.


Hi @Derek_Gervais,

Need your help on sending email to multiple CC and BCC.

$cc = "","","";
$bcc = "","","";

'message' => array(


Hi @clubstohire,

The cc and bcc fields must be arrays, since they can contain multiple email addresses. See the following example:

    "emailId": 2853049635,
    "message": {
        "to": "",
        "cc": [""],
        "bcc": [""]
    "contactProperties": [
            "name": "first_name",
            "value": "John"
    "customProperties": [
            "name": "item_1",
            "value": "something they bought"