duan7664 2019-05-29 03:03
浏览 44

如何在Sendinblue api v3中设置交易电子邮件属性?

So, I'm novice at best with php, but I've figured out how to set up and send transactional emails with sendinblue.

But for whatever reason, I can't seem to set the attributes.

This is really the only line of the code that I can't seem to get to work.

$sendEmail['attributes'] = array('FIRSTNAME' => "STEVE");$sendEmail['attributes'] = array('FIRSTNAME' => "STEVE"); I've also tried

$sendEmail['params'] = array('FIRSTNAME' => "STEVE");

and

$params['attributes'] = array('FIRSTNAME' => "STEVE");

...and probably 127 variations of the above, but I can't seem to get it it to work.

I also can't seem to figure out how to create a contact with php...

What is the "create contact" equivilent of this line of code:

$sendEmail = new \SendinBlue\Client\Model\SendEmail();

?

Like I said, my emails asre sending, but where I expect them to read "Dear STEVE," they read "Dear ,"

BELOW IS THE FULL CODE:

<?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;
}

?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
    • ¥20 软件测试决策法疑问求解答
    • ¥15 win11 23H2删除推荐的项目,支持注册表等
    • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
    • ¥15 qt6.6.3 基于百度云的语音识别 不会改
    • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
    • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
    • ¥15 lingo18勾选global solver求解使用的算法
    • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
    • ¥20 测距传感器数据手册i2c