A lot of code cleanup and code sanitation done.
This commit is contained in:
@@ -5,15 +5,13 @@ namespace bin\php\Classes;
|
||||
use PHPMailer\PHPMailer\Exception;
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
|
||||
require $_SERVER['DOCUMENT_ROOT'] . '/../vendor/autoload.php';
|
||||
require_once "{$_SERVER['DOCUMENT_ROOT']}/../vendor/autoload.php";
|
||||
|
||||
class mailBuilder
|
||||
{
|
||||
public $mail;
|
||||
public $subject;
|
||||
public $mailText;
|
||||
|
||||
private $portal_uuid;
|
||||
public PHPMailer $mail;
|
||||
public string $subject;
|
||||
public string $mailText;
|
||||
|
||||
function __construct()
|
||||
{
|
||||
@@ -44,38 +42,44 @@ class mailBuilder
|
||||
$this->mail->CharSet = 'UTF-8';
|
||||
$this->mail->Encoding = 'base64';
|
||||
|
||||
$this->mail->setFrom($mail_settings['mail_from_address'], $mail_settings['mail_from_name']);
|
||||
try {
|
||||
$this->mail->setFrom($mail_settings['mail_from_address'], $mail_settings['mail_from_name']
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
error_log($e->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function addAddress($address, $name)
|
||||
{
|
||||
$this->mail->addAddress($address, $name);
|
||||
}
|
||||
|
||||
function sendMail()
|
||||
function addAddress($address, $name): void
|
||||
{
|
||||
try {
|
||||
$this->mail->isHTML(true);
|
||||
$this->mail->addAddress($address, $name);
|
||||
} catch (Exception $e) {
|
||||
error_log($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
function sendMail(): bool
|
||||
{
|
||||
try {
|
||||
$this->mail->isHTML();
|
||||
$this->mail->Subject = $this->subject;
|
||||
$this->mail->Body = $this->mailHtmlBody();
|
||||
|
||||
$this->mail->send();
|
||||
return true;
|
||||
} catch (Exception $e) {
|
||||
} catch (Exception) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function mailHtmlBody()
|
||||
function mailHtmlBody(): array|false|string
|
||||
{
|
||||
$body = file_get_contents($_SERVER['DOCUMENT_ROOT'] . '/src/html/mailBody.html');
|
||||
|
||||
$bodyText = $this->mailText;
|
||||
|
||||
$body = str_replace('{{bodyText}}', $bodyText, $body);
|
||||
|
||||
|
||||
return $body;
|
||||
return str_replace('{{bodyText}}', $bodyText, $body);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user