PHP code example of jeffersongoncalves / laravel-brevo
1. Go to this page and download the library: Download jeffersongoncalves/laravel-brevo 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/ */
jeffersongoncalves / laravel-brevo example snippets
// config/brevo.php
return [
'api_url' => env('BREVO_API_URL', 'https://api.brevo.com/v3'),
'api_key' => env('BREVO_API_KEY', ''),
'default_limit' => env('BREVO_DEFAULT_LIMIT', 50),
];
use JeffersonGoncalves\Brevo\Facades\Brevo;
$account = Brevo::account();
// List (supports Brevo's contacts filters plus limit/offset)
$contacts = Brevo::contacts()->list(['limit' => 20]);
$contact = Brevo::contacts()->get('[email protected] '); // by id or email
$contact = Brevo::contacts()->create([
'email' => '[email protected] ',
'attributes' => ['FIRSTNAME' => 'Jane', 'LASTNAME' => 'Doe'],
'listIds' => [2, 3],
]);
Brevo::contacts()->update('[email protected] ', [
'attributes' => ['FIRSTNAME' => 'Janet'],
'listIds' => [4],
'unlinkListIds' => [3],
]);
Brevo::contacts()->delete('[email protected] ');
// Bulk import
Brevo::contacts()->import([
['email' => '[email protected] '],
['email' => '[email protected] '],
], listIds: [2]);
$lists = Brevo::lists()->list();
$list = Brevo::lists()->create('Newsletter', folderId: 1);
Brevo::lists()->update($list['id'], 'Renamed Newsletter');
$listContacts = Brevo::lists()->contacts($list['id']);
Brevo::lists()->addContacts($list['id'], ['[email protected] ']);
Brevo::lists()->removeContacts($list['id'], ['[email protected] ']);
Brevo::lists()->delete($list['id']);
Brevo::sendEmail(
senderEmail: '[email protected] ',
senderName: 'Acme',
to: [['email' => '[email protected] ', 'name' => 'Jane']],
subject: 'Welcome!',
htmlContent: '<p>Hi Jane</p>',
tags: ['welcome'],
);
Brevo::sendSms(
sender: 'Acme',
recipient: '+15555550100',
content: 'Your code is 123456',
);
$campaigns = Brevo::campaigns()->list(['status' => 'sent']);
$campaign = Brevo::campaigns()->create(
name: 'Summer Sale',
sender: ['name' => 'Acme', 'email' => '[email protected] '],
subject: 'Big Sale',
htmlContent: '<p>Save 20%</p>',
listIds: [2, 3],
);
Brevo::campaigns()->update($campaign['id'], ['subject' => 'Updated subject']);
Brevo::campaigns()->sendTest($campaign['id'], ['[email protected] ']);
Brevo::campaigns()->sendNow($campaign['id']);
Brevo::campaigns()->delete($campaign['id']);
Brevo::smsCampaigns()->list(['status' => 'sent']);
Brevo::senders()->list();
Brevo::senders()->create('Acme', '[email protected] ');
use JeffersonGoncalves\Brevo\Exceptions\BrevoException;
try {
Brevo::contacts()->get('[email protected] ');
} catch (BrevoException $e) {
logger()->error($e->getMessage(), $e->errorBody());
}
bash
php artisan vendor:publish --tag=brevo-config