Skip to content

Instantly share code, notes, and snippets.

@saqueib
Created June 14, 2024 01:10
Show Gist options
  • Save saqueib/2a249a8e888a74588b87962a37970421 to your computer and use it in GitHub Desktop.
Save saqueib/2a249a8e888a74588b87962a37970421 to your computer and use it in GitHub Desktop.
<?php
namespace App\Services;
use App\Services\Contracts\CRM as CRMContract;
class CRM implements CRMContract
{
public function sendEmail(array $contactIds, $emailEntry) : array
{
$htmlContent = $emailEntry->content;
// replace escaped braces in html content
$htmlContent = strtr($htmlContent, [
'%5B%5B' => '[[', // [[
'%5D%5D' => ']]', // ]]
'%7B%7B' => '{{', // {{
'%7D%7D' => '}}', // }}
]);
$emailPayload = [
'contacts' => $contactIds,
'html_content' => base64_encode($htmlContent),
'plain_content' => base64_encode($this->htmlToText($htmlContent)),
'subject' => $emailEntry->subject,
'user_id' => $emailEntry->from ? intval($emailEntry->from->value()) : self::KEAP_USER_ID,
];
return $this->keapApi()
->post("emails/queue", $emailPayload)
->json();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment