isValidPhpMailer(); $this->mail = new $this->phpMailerNs(); $this->mail->CharSet = "UTF-8"; $this->mail->ContentType = 'text/html'; $this->mail->Encoding = "8bit"; $this->loadWHMCSMailerConfig(); } protected function isValidPhpMailer() { if(class_exists('\\PHPMailer')) { $this->phpMailerNs = '\\PHPMailer'; return; } if(class_exists('\\PHPMailer\\PHPMailer\\PHPMailer')) { $this->phpMailerNs = '\\PHPMailer\\PHPMailer\\PHPMailer'; return; } throw new Exception('There is no PHPMailer class'); } public function __call($name, $arguments) { call_user_func_array(array($this->mail, $name), $arguments); } public function loadWHMCSMailerConfig() { $mailConfig = configuration\configuration::bySetting('MailConfig')->value; if(!empty($mailConfig)) { $configuration = json_decode(decrypt($mailConfig)); $this->mail->Host = $configuration->configuration->host; $this->mail->Port = $configuration->configuration->port; $this->mail->Username = $configuration->configuration->username; $this->mail->Password = $configuration->configuration->password; $this->mail->SMTPSecure = $configuration->configuration->secure; } else { $this->mail->Host = configuration\configuration::bySetting('SMTPHost')->value; $this->mail->Port = configuration\configuration::bySetting('SMTPPort')->value; $this->mail->Username = configuration\configuration::bySetting('SMTPUsername')->value; $this->mail->Password = decrypt(configuration\configuration::bySetting('SMTPPassword')->value); $this->mail->SMTPSecure = configuration\configuration::bySetting('SMTPSSL')->value; } $this->mail->mailType = configuration\configuration::bySetting('MailType')->value; $this->mail->setFrom(configuration\configuration::bySetting('SystemEmailsFromEmail')->value, configuration\configuration::bySetting('SystemEmailsFromName')->value); } public function send() { if($this->mail->mailType === 'smtp') { $this->mail->isSMTP(); $this->mail->SMTPAuth = true; } if(!$this->mail->send()) { \logModuleCall('DNS Manager', 'Mailer Error', $this->mail->ErrorInfo, "", array(), array(), array()); } } public function sendWHMCSTemplate($name, $type = 'admin', $relid = false) { $template = emailtemplate\repository::factory()->byName($name)->byType($type)->one(); if($template === false) { return; } $this->loadVariables('other'); $this->sendFromSmartyTemplate(html_entity_decode($template->subject), html_entity_decode($template->message)); } public function sendFromSmartyTemplate($subject, $message, $variables = false) { if($variables !== false) { $this->addVariables($variables); } $message = SmartyHelper::fetchFromString($message, $this->vars); $this->mail->Subject = $subject; $this->mail->Body = $message; $this->send(); } public function loadVariables($type, $relid = false) { switch($type) { case 'other': $obj = new Other(); break; } $this->addVariables($obj->getMergeFields()); } public function addVariable($name, $value) { $this->vars[$name] = $value; } public function addVariables($vars) { foreach($vars as $k => $v) { $this->addVariable($k, $v); } } }