mirror of
https://github.com/myronblair/epictravelexpeditions
synced 2026-06-30 17:50:08 -05:00
Switch email to CyberMail API (orbishosting.com domain)
This commit is contained in:
+11
-13
@@ -1,33 +1,31 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* Epic Travel Expeditions — SendGrid Mailer
|
* Epic Travel Expeditions — CyberMail Mailer
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function sendgridSend(string $toEmail, string $toName, string $subject, string $htmlBody, string $textBody = ''): bool {
|
function sendgridSend(string $toEmail, string $toName, string $subject, string $htmlBody, string $textBody = ''): bool {
|
||||||
$apiKey = defined('SENDGRID_API_KEY') ? SENDGRID_API_KEY : '';
|
$apiKey = defined('CYBERMAIL_API_KEY') ? CYBERMAIL_API_KEY : '';
|
||||||
if (!$apiKey || strpos($apiKey, 'YOUR_KEY') !== false) {
|
if (!$apiKey || strpos($apiKey, 'YOUR_KEY') !== false) {
|
||||||
error_log('[EpicTravel mailer] SENDGRID_API_KEY not configured');
|
error_log('[EpicTravel mailer] CYBERMAIL_API_KEY not configured');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$payload = json_encode([
|
$payload = [
|
||||||
'personalizations' => [['to' => [['email' => $toEmail, 'name' => $toName]]]],
|
|
||||||
'from' => [
|
'from' => [
|
||||||
'email' => defined('MAIL_FROM') ? MAIL_FROM : 'noreply@epictravelexpeditions.com',
|
'email' => defined('MAIL_FROM') ? MAIL_FROM : 'noreply@epictravelexpeditions.com',
|
||||||
'name' => defined('MAIL_FROM_NAME') ? MAIL_FROM_NAME : 'Epic Travel Expeditions',
|
'name' => defined('MAIL_FROM_NAME') ? MAIL_FROM_NAME : 'Epic Travel Expeditions',
|
||||||
],
|
],
|
||||||
|
'to' => [['email' => $toEmail, 'name' => $toName]],
|
||||||
'subject' => $subject,
|
'subject' => $subject,
|
||||||
'content' => array_values(array_filter([
|
'html' => $htmlBody,
|
||||||
$textBody ? ['type' => 'text/plain', 'value' => $textBody] : null,
|
];
|
||||||
['type' => 'text/html', 'value' => $htmlBody],
|
if ($textBody) $payload['text'] = $textBody;
|
||||||
])),
|
|
||||||
]);
|
|
||||||
|
|
||||||
$ch = curl_init('https://api.sendgrid.com/v3/mail/send');
|
$ch = curl_init('https://platform.cyberpersons.com/email/v1/send');
|
||||||
curl_setopt_array($ch, [
|
curl_setopt_array($ch, [
|
||||||
CURLOPT_RETURNTRANSFER => true,
|
CURLOPT_RETURNTRANSFER => true,
|
||||||
CURLOPT_POST => true,
|
CURLOPT_POST => true,
|
||||||
CURLOPT_POSTFIELDS => $payload,
|
CURLOPT_POSTFIELDS => json_encode($payload),
|
||||||
CURLOPT_HTTPHEADER => [
|
CURLOPT_HTTPHEADER => [
|
||||||
'Authorization: Bearer ' . $apiKey,
|
'Authorization: Bearer ' . $apiKey,
|
||||||
'Content-Type: application/json',
|
'Content-Type: application/json',
|
||||||
@@ -41,7 +39,7 @@ function sendgridSend(string $toEmail, string $toName, string $subject, string $
|
|||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
|
|
||||||
if ($httpCode === 202) return true;
|
if ($httpCode === 202) return true;
|
||||||
error_log('[EpicTravel mailer] SendGrid HTTP ' . $httpCode . ' — ' . $response);
|
error_log('[EpicTravel mailer] CyberMail HTTP ' . $httpCode . ' — ' . $response);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user