0

我尝试使用 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;
}
?>

我有以下错误:

解析错误:语法错误,意外的 '?',期望变量 (T_VARIABLE) 在 D:...\sendinblueV3\vendor\guzzlehttp\guzzle\src\Client.php 第 203 行

因为这条线

$apiInstance = ....

所以我删除了“?” 在 Client.php 的第 203 行:

public function getConfig(?string $option = null)

然后,我又犯了一个错误:

解析错误:语法错误,意外的 'const' (T_CONST),期望变量 (T_VARIABLE) 在 D:\Dropbox\www\ifrb\IFRBTP77\sendinblueV3\vendor\guzzlehttp\guzzle\src\ClientInterface.php 第 19 行

如果有人明白问题出在哪里......

谢谢你,奥利维尔。

编辑 :

我已经按照@David Wolf 的建议安装了作曲家。但是跑步的时候

C:\Windows\System32>composer 需要 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 版本。

4

1 回答 1

0

下载 API Wrapper 将不起作用,因为它本身具有依赖项(它依赖的其他代码),而您尚未安装。

存档您正在尝试做的最简单和最佳实践的方法是使用作曲家。

  1. 下载并安装作曲家
  2. composer require sendinblue/api-v3-sdk "8.x.x"

最后一个命令将自动为您安装所有依赖项并生成所需的自动加载器。

如果您是作曲家的新手,我建议您查看作曲家网站上的入门部分。

于 2022-02-08T23:09:54.460 回答