mirror of
https://github.com/myronblair/tomsjavajive
synced 2026-06-30 17:50:32 -05:00
Switch sendEmail() in functions.php to CyberMail API
This commit is contained in:
+20
-32
@@ -326,48 +326,36 @@ function getCartTotal() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send email using SendGrid
|
* Send email via CyberMail API
|
||||||
*/
|
*/
|
||||||
function sendEmail($to, $subject, $htmlContent, $textContent = '') {
|
function sendEmail($to, $subject, $htmlContent, $textContent = '') {
|
||||||
if (empty(SENDGRID_API_KEY)) {
|
$apiKey = defined('CYBERMAIL_API_KEY') ? CYBERMAIL_API_KEY : '';
|
||||||
return false;
|
if (!$apiKey) return false;
|
||||||
}
|
|
||||||
|
|
||||||
$data = [
|
$payload = [
|
||||||
'personalizations' => [
|
'from' => ['email' => SENDER_EMAIL, 'name' => SENDER_NAME],
|
||||||
[
|
|
||||||
'to' => [['email' => $to]],
|
'to' => [['email' => $to]],
|
||||||
'subject' => $subject
|
'subject' => $subject,
|
||||||
]
|
'html' => $htmlContent,
|
||||||
],
|
|
||||||
'from' => [
|
|
||||||
'email' => SENDER_EMAIL,
|
|
||||||
'name' => SENDER_NAME
|
|
||||||
],
|
|
||||||
'content' => [
|
|
||||||
['type' => 'text/html', 'value' => $htmlContent]
|
|
||||||
]
|
|
||||||
];
|
];
|
||||||
|
if ($textContent) $payload['text'] = $textContent;
|
||||||
|
|
||||||
if ($textContent) {
|
$ch = curl_init('https://platform.cyberpersons.com/email/v1/send');
|
||||||
array_unshift($data['content'], ['type' => 'text/plain', 'value' => $textContent]);
|
curl_setopt_array($ch, [
|
||||||
}
|
CURLOPT_RETURNTRANSFER => true,
|
||||||
|
CURLOPT_POST => true,
|
||||||
$ch = curl_init();
|
CURLOPT_POSTFIELDS => json_encode($payload),
|
||||||
curl_setopt($ch, CURLOPT_URL, 'https://api.sendgrid.com/v3/mail/send');
|
CURLOPT_HTTPHEADER => [
|
||||||
curl_setopt($ch, CURLOPT_POST, true);
|
'Authorization: Bearer ' . $apiKey,
|
||||||
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
|
'Content-Type: application/json',
|
||||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
],
|
||||||
'Authorization: Bearer ' . SENDGRID_API_KEY,
|
CURLOPT_TIMEOUT => 20,
|
||||||
'Content-Type: application/json'
|
CURLOPT_SSL_VERIFYPEER => false,
|
||||||
]);
|
]);
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
||||||
|
|
||||||
$response = curl_exec($ch);
|
$response = curl_exec($ch);
|
||||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
|
return $httpCode === 202;
|
||||||
return $httpCode >= 200 && $httpCode < 300;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user