1. Go to this page and download the library: Download getbrevo/brevo-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/ */
getbrevo / brevo-php example snippets
// v4
$client->event->createBatchEvents($eventsArray);
// v5
use Brevo\Event\Requests\CreateBatchEventsRequest;
$client->event->createBatchEvents(
new CreateBatchEventsRequest(['events' => $eventsArray])
);
use Brevo\Client\Configuration;
use Brevo\Client\Api\TransactionalEmailsApi;
use Brevo\Client\Model\SendSmtpEmail;
$config = Configuration::getDefaultConfiguration()->setApiKey('api-key', 'xkeysib-xxx');
$api = new TransactionalEmailsApi(new \GuzzleHttp\Client(), $config);
$message = new SendSmtpEmail();
$message->setSubject('First email');
$message->setTextContent('Hello world!');
$message->setSender(['name' => 'Bob Wilson', 'email' => '[email protected]']);
$message->setTo([['email' => '[email protected]', 'name' => 'Sarah Davis']]);
$api->sendTransacEmail($message);
use Brevo\Brevo;
use Brevo\TransactionalEmails\Requests\SendTransacEmailRequest;
use Brevo\TransactionalEmails\Types\SendTransacEmailRequestSender;
use Brevo\TransactionalEmails\Types\SendTransacEmailRequestToItem;
$brevo = new Brevo('xkeysib-xxx');
$brevo->transactionalEmails->sendTransacEmail(
new SendTransacEmailRequest([
'subject' => 'First email',
'textContent' => 'Hello world!',
'sender' => new SendTransacEmailRequestSender([
'name' => 'Bob Wilson',
'email' => '[email protected]',
]),
'to' => [
new SendTransacEmailRequestToItem([
'email' => '[email protected]',
'name' => 'Sarah Davis',
]),
],
])
);
namespace Example;
use Brevo\Brevo;
use Brevo\TransactionalEmails\Requests\SendTransacEmailRequest;
use Brevo\TransactionalEmails\Types\SendTransacEmailRequestSender;
use Brevo\TransactionalEmails\Types\SendTransacEmailRequestToItem;
$client = new Brevo(
apiKey: '<value>',
);
$client->transactionalEmails->sendTransacEmail(
new SendTransacEmailRequest([
'htmlContent' => '<html><head></head><body><p>Hello,</p>This is my first transactional email sent from Brevo.</p></body></html>',
'sender' => new SendTransacEmailRequestSender([
'email' => '[email protected]',
'name' => 'Alex from Brevo',
]),
'subject' => 'Hello from Brevo!',
'to' => [
new SendTransacEmailRequestToItem([
'email' => '[email protected]',
'name' => 'John Doe',
]),
],
]),
);
use Brevo\Brevo;
use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Middleware;
use GuzzleHttp\MessageFormatter;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
$logger = new Logger('brevo');
$logger->pushHandler(new StreamHandler('php://stderr', Logger::DEBUG));
$stack = HandlerStack::create();
$stack->push(Middleware::log(
$logger,
new MessageFormatter('{method} {uri} → {code}')
));
$client = new Brevo('xkeysib-xxx', [
'client' => new Client(['handler' => $stack, 'timeout' => 5.0]),
]);
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.