Implemented PHPMailer and a small wrapper. It is possible to use PHPMailer without the wrapper.

This commit is contained in:
Abel Hoogeveen 2015-08-26 16:53:13 +02:00
parent 2ec5e8bafd
commit cc31f2d1c6
4 changed files with 122 additions and 2 deletions

View File

@ -0,0 +1,74 @@
<?php
namespace Module\Mailer;
use \FuzeWorks\Module;
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.
*/
class Main extends Module {
/**
* Array of all the active PHPMailer instances
* @access private
* @var Array of \PHPMailer
*/
private $mailers = array();
/**
* First function to get called. Initiates all module variables
* @access public
*/
public function onLoad() {
$this->cfg = $this->config->loadConfigFile('mailer', $this->getModulePath());
}
/**
* Return one of the instances of PHPMailer.
* If not found, it creates a new instance and returns that
* @access public
* @param String instance name
* @return \PHPMailer instance
*/
public function __get($name) {
if (!isset($this->mailers[$name])) {
$this->mailers[$name] = new PHPMailer();
// Set settings
$cfg = $this->cfg;
// First check what is enabled
if ($cfg->sendmail_enabled && !$cfg->smtp_enabled) {
$this->mailers[$name]->isSendmail();
} elseif (!$cfg->sendmail_enabled && $cfg->smtp_enabled) {
$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;
// 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];
}
}
?>

View File

@ -0,0 +1,26 @@
<?php
return array(
# Sendmail Settings
'sendmail_enabled' => true,
# SMTP Settings
'smtp_enabled' => false,
'smtp_host' => '',
'smtp_port' => 25,
'smtp_auth' => false,
'smtp_username' => '',
'smtp_password' => '',
/**
* 0 = off
* 1 = client messages
* 2 = client and server messages
*/
'smtp_debug_level' => 0,
# Common sender information
'sender_name' => '',
'sender_mail' => '',
);
?>

View File

@ -0,0 +1,18 @@
<?php
return array(
'module_class' => '\Module\Mailer\Main',
'module_file' => 'class.mailer.php',
'module_name' => 'Mailer',
'dependencies' => array(),
'name' => 'Mailer',
'description' => 'PHPMailer wrapper for FuzeWorks',
'author' => 'TechFuze',
'version' => '1.0.0',
'website' => 'http://fuzeworks.techfuze.net/',
'date_created' => '08-07-2015',
'date_updated' => '08-07-2015',
);

View File

@ -1,8 +1,10 @@
{
"require": {
"php": ">=5.3.0"
"php": ">=5.3.0",
"phpmailer/phpmailer": "~5.2"
},
"require-dev": {
"phpunit/phpunit": "4.7.*"
"phpunit/phpunit": "4.7.*",
"apigen/apigen": "^4.1"
}
}