Switch sendEmail() in functions.php to CyberMail API

This commit is contained in:
2026-05-29 15:02:17 +00:00
parent d30851e3ec
commit 25e96a3d5f
+21 -33
View File
@@ -326,48 +326,36 @@ function getCartTotal() {
}
/**
* Send email using SendGrid
* Send email via CyberMail API
*/
function sendEmail($to, $subject, $htmlContent, $textContent = '') {
if (empty(SENDGRID_API_KEY)) {
return false;
}
$apiKey = defined('CYBERMAIL_API_KEY') ? CYBERMAIL_API_KEY : '';
if (!$apiKey) return false;
$data = [
'personalizations' => [
[
'to' => [['email' => $to]],
'subject' => $subject
]
],
'from' => [
'email' => SENDER_EMAIL,
'name' => SENDER_NAME
],
'content' => [
['type' => 'text/html', 'value' => $htmlContent]
]
$payload = [
'from' => ['email' => SENDER_EMAIL, 'name' => SENDER_NAME],
'to' => [['email' => $to]],
'subject' => $subject,
'html' => $htmlContent,
];
if ($textContent) $payload['text'] = $textContent;
if ($textContent) {
array_unshift($data['content'], ['type' => 'text/plain', 'value' => $textContent]);
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.sendgrid.com/v3/mail/send');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer ' . SENDGRID_API_KEY,
'Content-Type: application/json'
$ch = curl_init('https://platform.cyberpersons.com/email/v1/send');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode($payload),
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . $apiKey,
'Content-Type: application/json',
],
CURLOPT_TIMEOUT => 20,
CURLOPT_SSL_VERIFYPEER => false,
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return $httpCode >= 200 && $httpCode < 300;
return $httpCode === 202;
}
/**