86 lines
2.5 KiB
PHP
86 lines
2.5 KiB
PHP
<?php // THIS CLASS ENFORCES GDPR COMPLIANCE. USING A WORKAROUND FOR THIS CONSTITUTES A VIOLATION OF THE SPACEJEWEL TERMS OF SERVICE.
|
|
|
|
|
|
|
|
|
|
|
|
// This mailer won't let you mail anyone unless they are registered as a customer to prevent GDPR violation.
|
|
// Additionally, it doesn't let you send anything else other than mandatory email (like service downtime notifications) unless
|
|
// they explicitly provided GDPR consent
|
|
class Emailer
|
|
{
|
|
private $Customer;
|
|
|
|
|
|
private $CustomerEmail;
|
|
|
|
|
|
private $CustomerID;
|
|
|
|
|
|
private $Envelope;
|
|
|
|
|
|
private $Mailer;
|
|
|
|
// Initialize mailer for this customer ID
|
|
public function __construct($CustomerEmail)
|
|
{
|
|
|
|
$this->Customer = new Customer();
|
|
|
|
// WARNIMG: Function might return wrong data, use var_dump to inspect
|
|
$CID = $this->Customer->translateEmailToID($CustomerEmail);
|
|
$this->CustomerId = $CID;
|
|
// We might want to use $CID in this method, so shortening isn't feasible here
|
|
|
|
|
|
if(!$this->Customer->customerExists($CustomerEmail))
|
|
{
|
|
// Customer doesn't exist, fail here
|
|
throw new Exception("Fatal error! Sending an email to an unregistered person is not allowed (GDPR Error Code: #1). A customer can be registered by purchasing a subscription");
|
|
}
|
|
|
|
$this->prepareMailerEnvelope();
|
|
|
|
}
|
|
|
|
private function prepareMailerEnvelope()
|
|
{
|
|
$config = new Config();
|
|
$cConfigArray = $config->getConfig();
|
|
|
|
$username = $cConfigArray['mailer']['username'];
|
|
$password = $cConfigArray['mailer']['password'];
|
|
$hostname = $cConfigArray['mailer']['hostname'];
|
|
$port = $cConfigArray['mailer']['port'];
|
|
|
|
$connStr = 'tls://' . $username . ":" . $password . "@" . $hostname . ":" . $port;
|
|
|
|
$this->Envelope = new ByJG\Mail\Envelope();
|
|
|
|
\ByJG\Mail\MailerFactory::registerMailer('smtp', \ByJG\Mail\Wrapper\PHPMailerWrapper::class);
|
|
$this->Mailer = \ByJG\Mail\MailerFactory::create($connStr);
|
|
|
|
$this->Mailer->setFrom("noreply@spacejewel-hosting.com", "Spacejewel Billing System");
|
|
$this->Mailer->addTo($this->CustomerEmail);
|
|
|
|
}
|
|
|
|
public function addSubject($subject)
|
|
{
|
|
|
|
$this->Mailer->setSubject($subject);
|
|
|
|
}
|
|
|
|
public function setBody($body)
|
|
{
|
|
$this->Mailer->setBody($body);
|
|
}
|
|
|
|
public function sendEnvelope()
|
|
{
|
|
$Mailer->send($this->Envelope);
|
|
}
|
|
} |