Files
api/services/nginx/app/classes/email.php
T
Jepp9350 555d4e9918 Add comprehensive backup functionality and refactor email handling
Implemented server, database, and environment backups with configurable modules. Introduced new routes and configuration classes for backups alongside improved zip and S3 storage. Replaced PHPMailer with a cURL-based email service for streamlined message sending.
2025-02-11 17:41:57 +01:00

61 lines
1.6 KiB
PHP

<?php
namespace classes;
require_once WD . '/modules/email/email_c.php';
use email\email_c;
use interfaces\email_i;
class email implements email_i
{
/**
* Configuration for the email service
* @var email_c
*/
public email_c $config;
public function __construct()
{
$this->config = new email_c();
}
public function testConfigRequest(string $test_recipient): string
{
if ($test_recipient) {
try {
$this->sendEmail($test_recipient, 'Test email', 'This is a test email');
return 'Email sent successfully to ' . $test_recipient;
} catch (\Exception $e) {
return 'Email error: ' . $e->getMessage();
}
} else {
return 'No test recipient provided';
}
}
private function sendEmail($to, $subject, $message): void
{
// Send POST request to email service
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://maintenancemode.cloud/mailer.php');
curl_setopt($ch, CURLOPT_POST, 1);
// Add the data to the request
curl_setopt($ch, CURLOPT_POSTFIELDS, [
'recipient' => $to,
'subject' => $subject,
'message' => $message,
]);
// Return the response instead of outputting it
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Execute the POST request
$response = curl_exec($ch);
// Close cURL resource
curl_close($ch);
// Check for errors
if ($response === false) {
throw new \Exception('Curl error: ' . curl_error($ch));
}
}
}