php - 如何在 Sendinblue api v3 中设置交易电子邮件属性?
问题描述
所以,我充其量是 php 的新手,但我已经知道如何使用 sendinblue 设置和发送交易电子邮件。
但无论出于何种原因,我似乎无法设置属性。
这确实是我似乎无法开始工作的唯一代码行。
$sendEmail['attributes'] = array('FIRSTNAME' => "STEVE");$sendEmail['attributes'] = array('FIRSTNAME' => "STEVE"); 我也试过
$sendEmail['params'] = array('FIRSTNAME' => "STEVE");
和
$params['attributes'] = array('FIRSTNAME' => "STEVE");
...可能还有上述的 127 种变体,但我似乎无法让它发挥作用。
我似乎也无法弄清楚如何使用 php 创建联系人...
这行代码的“创建联系人”等价物是什么:
$sendEmail = new \SendinBlue\Client\Model\SendEmail();
?
就像我说的,我的电子邮件正在发送,但我希望他们阅读“亲爱的史蒂夫”,他们阅读“亲爱的”
以下是完整代码:
<?php
# Include the SendinBlue library\
require_once('../vendor/autoload.php');
# Instantiate the client\
$config = SendinBlue\Client\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'MY API KEY HERE');
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
// $config = SendinBlue\Client\Configuration::getDefaultConfiguration()->setApiKeyPrefix('api-key', 'Bearer');
// Configure API key authorization: partner-key
$config = SendinBlue\Client\Configuration::getDefaultConfiguration()->setApiKey('partner-key', 'MY API KEY HERE');
// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
// $config = SendinBlue\Client\Configuration::getDefaultConfiguration()->setApiKeyPrefix('partner-key', 'Bearer');
$apiInstance = new SendinBlue\Client\Api\SMTPApi(
// If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
// This is optional, `GuzzleHttp\Client` will be used as default.
new GuzzleHttp\Client(),
$config
);
$templateId = 2; // int | Id of the template
$sendEmail = new \SendinBlue\Client\Model\SendEmail(); // \SendinBlue\Client\Model\SendEmail |
$sendEmail['emailTo'] = array("test@example.com");
$params['attributes'] = array('FIRSTNAME' => "STEVE"); //THIS IS THE LINE OF CODE THAT ISN'T WORKING.
//$mail->setFrom('info@myeasy.wedding', 'My Easy Wedding');
try {
$result = $apiInstance->sendTemplate($templateId, $sendEmail);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling SMTPApi->sendTemplate: ', $e->getMessage(), PHP_EOL;
}
?>
解决方案
您需要使用sendTransacEmail()
它,它与 PARAM 一起使用。需要在模板中添加代码{{ params.FIRSTNAME }}
完整的 API 代码
$config = SendinBlue\Client\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'MY API KEY HERE');
$apiInstance = new SendinBlue\Client\Api\TransactionalEmailsApi(
// If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
// This is optional, `GuzzleHttp\Client` will be used as default.
new GuzzleHttp\Client(),
$config
);
$sendEmail = new SendinBlue\Client\Model\SendSmtpEmail();
$sendEmail['to'] = [["email" => 'test@example.com', "name" => 'test']];
$sendEmail['templateId'] = 2;
$sendEmail['params'] = ['FIRSTNAME' => 'Test'];
try {
$response = $apiInstance->sendTransacEmail($sendEmail);
print_r($response);
} catch (Exception $e) {
echo 'Exception when calling AccountApi->getAccount: ', $e->getMessage(), PHP_EOL;
}
推荐阅读
- excel - 如何在 excel 中使用多个 vlookup 标准?
- swift - 无法使用 iOS 应用程序读取蓝牙服务 (BLE) 中的用户定义特征
- excel - 创建数据透视表不适用于新的 Excel 版本
- javascript - 有没有办法将服务器端 JS 嵌入 HTML(如 PHP)?
- angular - 检测到循环依赖中的警告:
- c# - 如何使用“编辑器协程”包在编辑器中启动协程?
- zeromq - 使用 zmqpp 进行零拷贝消息传递
- linux - 等效于 head/tail 命令以显示头/尾或一行
- c# - 如何将 IHttpContextAccessor 作为参数传递给 Activator.createinstance 方法中的 crating 实例?
- android - 出现类似“Android 资源链接失败”的错误