我试图发送带有属性的交易性电子邮件,但是Sendinblue的返回
400坏请求{“代码”:“invalid_parameter”,“消息”:“属性无效”}
在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%)。
如果我不包括属性,它就能工作.
发布于 2020-11-01 12:55:29
<?php
require_once(__DIR__ . '/vendor/autoload.php');
$config = SendinBlue\Client\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'YOUR API KEY');
$apiInstance = new SendinBlue\Client\Api\TransactionalEmailsApi(
new GuzzleHttp\Client(),
$config
);
$templateId = 1;
$sendEmail = new \SendinBlue\Client\Model\SendEmail()
$sendEmail['emailTo'] = array('example@example.com');
$sendEmail['emailCc'] = array('example1@example1.com');
$sendEmail['headers'] = array('Some-Custom-Name' => 'unique-id-1234');
$sendEmail['attributes'] = array('FNAME' => 'Jane', 'LNAME' => 'Doe');
$sendEmail['replyTo'] = 'replyto@domain.com';
$sendEmail['attachmentUrl'] = 'https://example.net/upload-file.pdf';
try {
$result = $apiInstance->sendTemplate($templateId, $sendEmail);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling TransactionalEmailsApi->sendTemplate: ', $e->getMessage(), PHP_EOL;
}
?>请试试这个密码。你可以在https://developers.sendinblue.com/reference#sendtemplate-1上找到例子
https://stackoverflow.com/questions/58594481
复制相似问题