因此,我充其量是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();
?
就像我说的那样,我的电子邮件发送时很差劲,但是我希望它们显示为“ Dear STEVE”,而它们显示为“ Dear”,
下面是完整代码:
<?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 :(得分:0)
您需要使用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;
}
答案 1 :(得分:0)
尝试使用FNAME
代替FIRSTNAME
参考
<?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;
}
?>
中找到更多示例