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); } }