1. Go to this page and download the library: Download cloudcontactai/ccai-php library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
loudContactAI\CCAI\CCAI;
use CloudContactAI\CCAI\SMS\Account;
// Initialize the client
$ccai = new CCAI([
'clientId' => 'YOUR-CLIENT-ID',
'apiKey' => 'YOUR-API-KEY'
]);
// Send a single SMS
$response = $ccai->sms->sendSingle(
firstName: 'John',
lastName: 'Doe',
phone: '+15551234567',
message: 'Hello ${firstName}, this is a test message!',
title: 'Test Campaign'
);
echo "Message sent with ID: " . $response->id . "\n";
// Send to multiple recipients
$accounts = [
new Account('John', 'Doe', '+15551234567'),
new Account('Jane', 'Smith', '+15559876543')
];
$campaignResponse = $ccai->sms->send(
accounts: $accounts,
message: 'Hello ${firstName} ${lastName}, this is a test message!',
title: 'Bulk Test Campaign'
);
echo "Campaign sent with ID: " . $campaignResponse->campaignId . "\n";
// Send to multiple recipients using a template
$response = $ccai->sms->sendWithTemplate(
accounts: $accounts,
templateId: 12345, // the ID of the approved template
title: 'My Campaign'
);
// Send to a single recipient using a template
$response = $ccai->sms->sendSingleWithTemplate(
firstName: 'John',
lastName: 'Doe',
phone: '+15551234567',
templateId: 12345,
title: 'My Campaign'
);
echo "Campaign sent with ID: " . $response->campaignId . "\n";
/**
* Simple example of sending an MMS message using the CCAI PHP library
*/
AI([
'clientId' => getenv('CCAI_CLIENT_ID') ?: 'YOUR_CLIENT_ID',
'apiKey' => getenv('CCAI_API_KEY') ?: 'YOUR_API_KEY'
]);
// Path to the image file you want to send
$filename = 'imagePHP.jpg';
$imagePath = __DIR__ . '/imagePHP.jpg';
$contentType = 'image/jpeg';
try {
// Send an MMS to a single recipient
$response = $ccai->mms->sendWithImage(
$imagePath,
$contentType,
[
[
'firstName' => 'Jane',
'lastName' => 'Doe',
'phone' => '+15555555555'
]
],
'Hi ${firstName} ${lastName}, testing a new campaign',
'MMS Content Test Message'
);
echo "MMS sent successfully! ID: " . $response->id . "\n";
} catch (\Exception $e) {
echo "Error: " . $e->getMessage() . "\n";
}
loudContactAI\CCAI\CCAI;
use CloudContactAI\CCAI\Email\EmailAccount;
// Initialize the client
$ccai = new CCAI([
'clientId' => 'YOUR-CLIENT-ID',
'apiKey' => 'YOUR-API-KEY'
]);
// Send a single email
$response = $ccai->email->sendSingle(
firstName: 'John',
lastName: 'Doe',
email: '[email protected]',
subject: 'Welcome to Our Service',
htmlContent: '<p>Hello John,</p><p>Thank you for signing up!</p>',
senderEmail: '[email protected]',
replyEmail: '[email protected]',
senderName: 'Your Company',
title: 'Welcome Email'
);
echo "Email sent successfully!\n";
// Send email campaign to multiple recipients
$accounts = [
new EmailAccount('John', 'Doe', '[email protected]'),
new EmailAccount('Jane', 'Smith', '[email protected]')
];
$campaign = [
'accounts' => array_map(fn(EmailAccount $a) => $a->toArray(), $accounts),
'subject' => 'Monthly Newsletter',
'title' => 'July 2025 Newsletter',
'message' => '<h1>Hello ${firstName}!</h1><p>Monthly updates...</p>',
'senderEmail' => '[email protected]',
'replyEmail' => '[email protected]',
'senderName' => 'Your Company Newsletter',
];
$response = $ccai->email->sendCampaign($campaign);
echo "Campaign sent successfully!\n";
loudContactAI\CCAI\CCAI;
$ccai = new CCAI([
'clientId' => 'YOUR-CLIENT-ID',
'apiKey' => 'YOUR-API-KEY'
]);
// Opt a contact out of text messages (by phone number)
$result = $ccai->contact->setDoNotText(true, null, '+15551234567');
echo "Opted out: " . json_encode($result) . "\n";
// Opt a contact back in
$ccai->contact->setDoNotText(false, null, '+15551234567');
// Opt out by contactId
$ccai->contact->setDoNotText(true, 'contact-abc-123', null);