Codex's updates...

This commit is contained in:
2026-10-18 19:27:17 -04:00
parent a1643eb1b7
commit 02223083f6
338 changed files with 14757 additions and 7986 deletions
+23 -48
View File
@@ -9,6 +9,13 @@ use PHPMailer\PHPMailer\Exception;
class Email extends Base {
public function sendPasswordReset(array $user, string $url): bool {
$xml = new SimpleXMLElement('<users><record/></users>');
$xml->record->user_name = $user['user_first_name'] ?: $user['user_name'];
$body = $this->applyXSL($xml, $this->getXSL('emailPasswordResetLink'), ['RESET_URL' => $url]);
return $this->sendEmail((string) $user['user_email'], self::APPLICATION_NAME . ' - Password reset', $body);
}
// Variables.
private $current_user_name = "";
@@ -32,45 +39,14 @@ class Email extends Base {
// Email a new users credentials
// =============================
public function emailNewUserCredentials($user, $password) {
if (!$user instanceof SimpleXMLElement) {
return;
}
// Prepare the email
$to = (string) $user->record->user_email;
$XSLParms['USER-TEMP-PASSWORD'] = $password;
$subject = "New User Credentials";
$message = $this->applyXSL($user, $this->getXSL("emailNewUserCredentials"), $XSLParms);
// Send the Email
$this->sendEmail($to, $subject, $message);
public function emailNewUserCredentials($user, $password = null) {
$this->emailUserPasswordResetLink($user);
}
// =================================
// Email a users Password Reset Link
// =================================
public function emailUserPasswordResetLink($user, $password) {
if (!$user instanceof SimpleXMLElement) {
return;
public function emailUserPasswordResetLink($user, $password = null) {
if ($user instanceof SimpleXMLElement) {
(new AuthService())->requestReset((string) $user->record->user_email);
}
// Prepare the email.
$XSLParms['USER-TEMP-PASSWORD'] = $password;
$to = (string) $user->record->user_email;
$subject = "Password Reset Request";
$message = $this->applyXSL($user, $this->getXSL("emailPasswordResetLink"), $XSLParms);
// Send the Email
$this->sendEmail($to, $subject, $message);
}
// =======================================
@@ -101,15 +77,17 @@ class Email extends Base {
//Server settings
$email->isSMTP();
$email->Host = $SmtpHost;
$email->Host = (string) $SmtpHost;
$email->SMTPAuth = true;
$email->Username = $SmtpUsername; // Your Gmail address
$email->Password = $SmtpPassword; // App password from Google
// $email->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // or 'tls'
$email->Port = $SmtpPort;
$email->Username = (string) $SmtpUsername;
$email->Password = (string) $SmtpPassword;
$email->Port = (int) $SmtpPort;
$email->SMTPSecure = $email->Port === 465 ? PHPMailer::ENCRYPTION_SMTPS : PHPMailer::ENCRYPTION_STARTTLS;
$email->Timeout = 15;
$email->CharSet = 'UTF-8';
$email->isHTML(true);
$email->SetFrom("info@onesourceits.com", "OneSource IT Solutions LLC");
$email->setFrom((string) ($settings->SmtpFromEmail ?? $settings->SmtpUserName), self::APPLICATION_NAME);
if (is_array($to)) {
foreach ($to as $address) {
@@ -125,6 +103,7 @@ class Email extends Base {
$email->Subject = $subject;
$email->Body = $message;
$email->AltBody = html_entity_decode(strip_tags(preg_replace('/<a\s+href="([^"]*)"[^>]*>(.*?)<\/a>/is', '$2 ($1)', $message)), ENT_QUOTES | ENT_HTML5, 'UTF-8');
if (is_array($attachments)) {
foreach ($attachments as $index => $item) {
@@ -139,13 +118,9 @@ class Email extends Base {
}
$success = $email->Send();
} catch (phpMailerException $e) {
} catch (\Throwable $e) {
(new Journal())->journalEntry($e->errorMessage());
$success = false;
} catch (Exception $e) {
(new Journal())->journalEntry($e->getMessage());
error_log('Email delivery failed: ' . $e->getMessage());
$success = false;
}