PHP code example of trimis / trimis-php
1. Go to this page and download the library: Download trimis/trimis-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/ */
trimis / trimis-php example snippets
Trimis\TrimisClient;
$client = new TrimisClient('YOUR_API_KEY');
// Send an email
$result = $client->sendEmail(
'[email protected] ',
'[email protected] ',
'Hello!',
'<h1>Hello World</h1>',
'Hello World'
);
if ($result['success']) {
echo "Email sent! " . json_encode($result['data']);
} else {
echo "Error: " . $result['error'];
}
// Send email
$result = $client->sendEmail(
'[email protected] ',
'[email protected] ',
'Welcome!',
'<h1>Welcome</h1>',
'Welcome',
true, // track opens
true // track clicks
);
// Send notification with template
$result = $client->sendNotification(
'[email protected] ',
'[email protected] ',
'welcome_email',
[
'name' => 'John Doe',
'activation_link' => 'https://app.com/activate?token=abc123'
]
);
// Get notification status
$notification = $client->getNotification('notif_123');
// Get VAPID key
$vapid = $client->getVapidKey();
// Subscribe user
$client->subscribePush(
'user123',
'web',
[
'subscription' => [
'endpoint' => 'https://fcm.googleapis.com/...',
'keys' => [
'p256dh' => '...',
'auth' => '...'
]
]
]
);
// Send push notification
$client->sendPush(
['user123', 'user456'],
'New Message',
'You have a new message',
'https://app.com/messages'
);
// Create conversation
$conversation = $client->createConversation(
'direct',
[
['user_id' => 'user1', 'name' => 'Alice'],
['user_id' => 'user2', 'name' => 'Bob']
]
);
// Send message
$client->sendMessage(
$conversation['data']['conversation_id'],
'user1',
'Hello!'
);
// Get messages
$messages = $client->getMessages($conversation['data']['conversation_id']);
// Mark as read
$client->markMessageRead('msg_123', 'user2');
// In your service provider or controller
use Trimis\TrimisClient;
$client = new TrimisClient(config('services.trimis.api_key'));
$client->sendEmail(...);
// In functions.php or as a plugin
use Trimis\TrimisClient;
$client = new TrimisClient(get_option('trimis_api_key'));
$client->sendEmail(...);
$result = $client->sendEmail(...);
if (!$result['success']) {
echo "Error: " . $result['error'];
echo "Status: " . ($result['status'] ?? 'N/A');
}
bash
composer