Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save lalainarahajason/c5bb0b53c9176908e3241c948b75091f to your computer and use it in GitHub Desktop.
Save lalainarahajason/c5bb0b53c9176908e3241c948b75091f to your computer and use it in GitHub Desktop.
Create transactional email with html as params
require_once(__DIR__ . '/vendor/autoload.php');
// Configure API key authorization: api-key
$config = SendinBlue\Client\Configuration::getDefaultConfiguration()->setApiKey('api-key', 'MY_API_KEY');
// 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');
// 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
);
try {
$categories = array("categories" => array(
array(
"name" => "<strong>Categorie A</strong><br/><a href='google.fr'> - Test sous categorie A",
"name" => "<strong>Categorie A</strong><br/><a href='google.fr'> - Test sous categorie A"
),
array(
"name" => "<strong>Categorie B</strong><br/><a href='google.fr'> - Test sous categorie B"
)
)
);
$email_campaigns['name'] = "Campaign sent via the API";
$email_campaigns['subject'] = "Test params email";
$email_campaigns['sender'] = array("name" => "Jon Doe", "email" => "[email protected]");
$email_campaigns['to'] = array(array("name" => "Marlen Martin", "email" => "[email protected]"));
$email_campaigns["htmlContent"] = "Congratulations! You successfully sent this example campaign via the Sendinblue API.";
$email_campaigns["templateId"] = 3;
$email_campaigns["params"] = $categories;
$email_campaigns["recipients"] = array("listIds"=> [7]);
$result = $apiInstance->sendTransacEmail($email_campaigns);
echo "<pre>";
print_r($result);
echo "</pre>";
} catch (Exception $e) {
echo 'Exception when calling AccountApi->getAccount: ', $e->getMessage(), PHP_EOL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment