API V3 と php を使用して、Sendinblue でトランザクション メールを送信しようとしています。
私はドキュメントhttps://github.com/sendinblue/APIv3-php-libraryに従おうとしましたが、次のような Stackoverflow に関する多くの投稿を読みました: How do I set transactional email attributes in Sendinblue api v3 ? .
composer で vendor/autoload.php を生成する方法がわからないので、 https://php-download.com で sendinblue/api-v3-sdk (公式の SendinBlue が提供する RESTFul API V3 php ライブラリ) をダウンロードしました。
私はこれらの行をテストしました:
<?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;
}
?>
そして、次のエラーが発生しました:
解析エラー: 構文エラー、予期しない '?'、D:...\sendinblueV3\vendor\guzzlehttp\guzzle\src\Client.php の 203 行目に変数 (T_VARIABLE) が必要です
この線のせいで
$apiInstance = ....
だから私は「?」を削除しました。Client.php の 203 行目:
public function getConfig(?string $option = null)
そして、私は別の間違いを犯しました:
解析エラー: 構文エラー、予期しない 'const' (T_CONST)、19 行目の D:\Dropbox\www\ifrb\IFRBTP77\sendinblueV3\vendor\guzzlehttp\guzzle\src\ClientInterface.php に変数 (T_VARIABLE) が必要です
誰かが問題がどこにあるかを理解していれば....
ありがとう、オリヴィエ。
編集 :
@David Wolfが提案したように、composerをインストールしました。でも走るときは
C:\Windows\System32>composer require sendinblue/api-v3-sdk "8.xx"
私のphpバージョンが原因でエラーが発生しました:
./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].
API v3 PHP ライブラリには PHP 5.6 以降が必要なので、これは興味深いことです。
また、サーバーで py php バージョンをアップグレードできません。