我尝试发送带有属性的事务性电子邮件,但 Sendinblue API 返回一个
400 错误请求 {"code":"invalid_parameter","message":"attributes are not valid"}
在 Sendinblue 文档中,他们说要使用json 对象和 set 方法。
/**
* Sets attributes
*
* @param object $attributes Pass the set of attributes to customize the template. For example, {\"FNAME\":\"Joe\", \"LNAME\":\"Doe\"}
*
* @return $this
*/
public function setAttributes($attributes)
{
$this->container['attributes'] = $attributes;
return $this;
}
下面,我发送电子邮件的代码,我使用他们的例子:
$templateId = 2; // int | Id of the template
$sendEmail = new \SendinBlue\Client\Model\SendEmail(); // \SendinBlue\Client\Model\SendEmail
$sendEmail->setEmailTo(array('example@mail.com')); //for stackoverflow
$sendEmail->setAttributes('{"LNAME":"John","FNAME":"Doe"}');
try {
$result = $apiInstance->sendTemplate($templateId, $sendEmail);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling AccountApi->getAccount: ', $e->getMessage(), PHP_EOL;
}
我的邮件模板中有我的属性(如%FNAME%)。
如果我不包含属性,它可以工作。