mirror of
https://github.com/myronblair/tomsjavajive
synced 2026-06-30 17:50:32 -05:00
Switch email to CyberMail API; integrations page manages API key via DB
This commit is contained in:
+15
-19
@@ -329,33 +329,29 @@ function getCartTotal() {
|
||||
* Send email via CyberMail API
|
||||
*/
|
||||
function sendEmail($to, $subject, $htmlContent, $textContent = '') {
|
||||
$apiKey = defined('CYBERMAIL_API_KEY') ? CYBERMAIL_API_KEY : '';
|
||||
if (!$apiKey) return false;
|
||||
|
||||
$payload = [
|
||||
'from' => ['email' => SENDER_EMAIL, 'name' => SENDER_NAME],
|
||||
'to' => [['email' => $to]],
|
||||
'subject' => $subject,
|
||||
'html' => $htmlContent,
|
||||
];
|
||||
$apiKey = getSetting('cybermail_api_key', defined('CYBERMAIL_API_KEY') ? CYBERMAIL_API_KEY : '');
|
||||
$from = getSetting('cybermail_from_email', 'noreply@tomsjavajive.com');
|
||||
$fromName = getSetting('cybermail_from_name', "Tom's Java Jive");
|
||||
if (!$apiKey) {
|
||||
error_log('[TJJ sendEmail] CYBERMAIL_API_KEY not configured');
|
||||
return false;
|
||||
}
|
||||
$payload = ['from' => ['email' => $from, 'name' => $fromName],
|
||||
'to' => [['email' => $to]], 'subject' => $subject, 'html' => $htmlContent];
|
||||
if ($textContent) $payload['text'] = $textContent;
|
||||
|
||||
$ch = curl_init('https://platform.cyberpersons.com/email/v1/send');
|
||||
curl_setopt_array($ch, [
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_POST => true,
|
||||
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,
|
||||
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . $apiKey, 'Content-Type: application/json'],
|
||||
CURLOPT_TIMEOUT => 20, CURLOPT_SSL_VERIFYPEER => false,
|
||||
]);
|
||||
$response = curl_exec($ch);
|
||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
return $httpCode === 202;
|
||||
if ($httpCode === 202) return true;
|
||||
error_log('[TJJ sendEmail] CyberMail HTTP ' . $httpCode . ' — ' . $response);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user