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 = SendinBlue\Client\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'xkeysib-my-key');
$apiInstance = new SendinBlue\Client\Api\TransactionalEmailsApi(
new GuzzleHttp\Client(),
$config
);
$sendSmtpEmail = new \SendinBlue\Client\Model\SendSmtpEmail();
$sendSmtpEmail['subject'] = 'Le sujet';
$sendSmtpEmail['htmlContent'] = '<html><body><h1>This is a transactional email </h1></body></html>';
$sendSmtpEmail['sender'] = array('name' => 'John Doe', 'email' => 'contact@domain.com');
$sendSmtpEmail['to'] = array(
array('email' => 'autre@domain2fr', 'name' => 'Jane Doe')
);
$sendSmtpEmail['replyTo'] = array('email' => 'replyto@domain.com', '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:...\sendinblueV3\vendor\guzzlehttp\guzzle\src\Client.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:\Dropbox\www\ifrb\IFRBTP77\sendinblueV3\vendor\guzzlehttp\guzzle\src\ClientInterface.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:\Windows\System32>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.