I try to send transactional emails with Sendinblue, using API V3 and php.
I’ve tried to follow the documentation https://github.com/sendinblue/APIv3-php-library and I’ve read a lot of posts on Stackoverflow, like this one : How do I set transactional email attributes in Sendinblue api v3?.
I don’t know how to generate vendor/autoload.php with composer, so I’ve downloaded
sendinblue/api-v3-sdk (Official SendinBlue provided RESTFul API V3 php library) on https://php-download.com.
I’ve tested these lines :
<?php
require_once('/vendor/autoload.php');
$config = SendinBlueClientConfiguration::getDefaultConfiguration()->setApiKey('api-key', 'xkeysib-my-key');
$apiInstance = new SendinBlueClientApiTransactionalEmailsApi(
new GuzzleHttpClient(),
$config
);
$sendSmtpEmail = new SendinBlueClientModelSendSmtpEmail();
$sendSmtpEmail['subject'] = 'Le sujet';
$sendSmtpEmail['htmlContent'] = '<html><body><h1>This is a transactional email </h1></body></html>';
$sendSmtpEmail['sender'] = array('name' => 'John Doe', 'email' => '[email protected]');
$sendSmtpEmail['to'] = array(
array('email' => 'autre@domain2fr', 'name' => 'Jane Doe')
);
$sendSmtpEmail['replyTo'] = array('email' => '[email protected]', 'name' => 'John Doe');
$sendSmtpEmail['headers'] = array('Some-Custom-Name' => 'unique-id-1234');
$sendSmtpEmail['params'] = array('parameter' => 'My param value', 'subject' => 'New Subject');
try {
$result = $apiInstance->sendTransacEmail($sendSmtpEmail);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling TransactionalEmailsApi->sendTransacEmail: ', $e->getMessage(), PHP_EOL;
}
?>
And I’ve got the following error :
Parse error: syntax error, unexpected ‘?’, expecting variable (T_VARIABLE) in D:…sendinblueV3vendorguzzlehttpguzzlesrcClient.php on line 203
because of this line
$apiInstance = ....
So I’ve removed the "?" on line 203 of Client.php :
public function getConfig(?string $option = null)
and then, I’ve another mistake :
Parse error: syntax error, unexpected ‘const’ (T_CONST), expecting variable (T_VARIABLE) in D:DropboxwwwifrbIFRBTP77sendinblueV3vendorguzzlehttpguzzlesrcClientInterface.php on line 19
If someone understand where is the problem ….
Thank you,
Olivier.
Edit :
I’ve installed composer as @David Wolf suggested to me.
But when running
C:WindowsSystem32>composer require sendinblue/api-v3-sdk "8.x.x"
I’ve an error due to my php version :
./composer.json has been created Running composer update
sendinblue/api-v3-sdk Loading composer repositories with package
information Updating dependencies Your requirements could not be
resolved to an installable set of packages.
Problem 1
- guzzlehttp/guzzle[7.4.0, ..., 7.4.1] require php ^7.2.5 || ^8.0 -> your php version (5.6.18) does not satisfy that requirement.
- sendinblue/api-v3-sdk v8.0.0 requires guzzlehttp/guzzle ^7.4.0 -> satisfiable by guzzlehttp/guzzle[7.4.0, 7.4.1].
- Root composer.json requires sendinblue/api-v3-sdk 8.x.x -> satisfiable by sendinblue/api-v3-sdk[v8.0.0].
That’s curious because API v3 Php Library requires PHP 5.6 and later.
And I can’t upgrade py php version on my server.
2
Answers
Downloading the API Wrapper won’t work, since itself has dependencies (other code it depends on), which you haven’t installed.
The easiest and best practice way to archive what you are trying to do is using composer.
composer require sendinblue/api-v3-sdk "8.x.x"
The last command will automatically install all dependencies for you and generate the needed autoloaders.
If you are new to composer I would suggest you checking out the getting started section on the composer website.
I am using the below code with simple CURL from PHP in my production server and working perfectly. Using composer I struggled a lot to manage library dependencies and finally figured it out using simple CURL.