. * * @author TechFuze * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) * @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/) * @license http://opensource.org/licenses/GPL-3.0 GPLv3 License * * @link http://fuzeworks.techfuze.net * @since Version 0.0.1 * * @version Version 0.0.1 */ namespace Module\Mailer; use FuzeWorks\Module; use FuzeWorks\ModuleException; use FuzeWorks\Config; use PHPMailer; /** * Main class for the Mailer module. * * This class is a simple wrapper for PHPMailer. It has a simple prepared config file and can create instances based on these config files. * * @author Abel Hoogeveen * @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net) */ class Main { use Module; /** * Array of all the active PHPMailer instances. * * @var array of \PHPMailer */ private $mailers = array(); /** * First function to get called. Initiates all module variables. */ public function onLoad() { if (!class_exists('\PHPMailer')) { throw new ModuleException('PHPMailer class not found! Is composer installed?', 1); } } /** * Return one of the instances of PHPMailer. * If not found, it creates a new instance and returns that. * * @param string instance name * * @return \PHPMailer instance */ public function __get($name) { if (!isset($this->mailers[$name])) { $this->mailers[$name] = new PHPMailer(); // Set settings $cfg = self::$cfg; // First check what is enabled if ($cfg->sendmail_enabled && !$cfg->smtp_enabled) { $this->mailers[$name]->isSendmail(); } elseif (!$cfg->sendmail_enabled && $cfg->smtp_enabled) { // Set up all the SMTP details $this->mailers[$name]->isSMTP(); $this->mailers[$name]->SMTPDebug = $cfg->smtp_debug_level; $this->mailers[$name]->Debugoutput = 'html'; $this->mailers[$name]->Host = $cfg->smtp_host; $this->mailers[$name]->Port = $cfg->smtp_port; // SMTP Authentication if ($cfg->smtp_auth) { $this->mailers[$name]->SMTPAuth = true; $this->mailers[$name]->Username = $cfg->smtp_username; $this->mailers[$name]->Password = $cfg->smtp_password; } // Set the sender correctly if ($cfg->sender_name != '' && $cfg->sender_mail != '') { $this->mailers[$name]->setFrom($cfg->sender_mail, $cfg->sender_name); } elseif ($cfg->sender_name == '' && $cfg->sender_mail != '') { $mail->From = $cfg->sender_mail; } } } return $this->mailers[$name]; } }