Implemented a new mailer library.

The old PHPMailer wrapper module has been replaced with a more lightweight library from CodeIgniter.

Supports the following feautures:
- Multiple Protocols: Mail, Sendmail, and SMTP
- TLS and SSL Encryption for SMTP
- Multiple recipients
- CC and BCCs
- HTML or Plaintext email
- Attachments
- Word wrapping
- Priorities
- BCC Batch Mode, enabling large email lists to be broken into small BCC batches.
- Email Debugging tools
This commit is contained in:
Abel Hoogeveen 2016-05-22 20:20:50 +02:00
parent dc5f830a0a
commit 02206f4bda
6 changed files with 2401 additions and 220 deletions

View File

@ -0,0 +1,55 @@
<?php
/**
* FuzeWorks.
*
* The FuzeWorks MVC PHP FrameWork
*
* Copyright (C) 2015 TechFuze
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @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
*/
return array (
'email_must_be_array' => 'The email validation method must be passed an array.',
'email_invalid_address' => 'Invalid email address: %s',
'email_attachment_missing' => 'Unable to locate the following email attachment: %s',
'email_attachment_unreadable' => 'Unable to open this attachment: %s',
'email_no_from' => 'Cannot send mail with no "From" header.',
'email_no_recipients' => 'You must include recipients: To, Cc, or Bcc',
'email_send_failure_phpmail' => 'Unable to send email using PHP mail(). Your server might not be configured to send mail using this method.',
'email_send_failure_sendmail' => 'Unable to send email using PHP Sendmail. Your server might not be configured to send mail using this method.',
'email_send_failure_smtp' => 'Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.',
'email_sent' => 'Your message has been successfully sent using the following protocol: %s',
'email_no_socket' => 'Unable to open a socket to Sendmail. Please check settings.',
'email_no_hostname' => 'You did not specify a SMTP hostname.',
'email_smtp_error' => 'The following SMTP error was encountered: %s',
'email_no_smtp_unpw' => 'Error: You must assign a SMTP username and password.',
'email_failed_smtp_login' => 'Failed to send AUTH LOGIN command. Error: %s',
'email_smtp_auth_un' => 'Failed to authenticate username. Error: %s',
'email_smtp_auth_pw' => 'Failed to authenticate password. Error: %s',
'email_smtp_data_failure' => 'Unable to send data: %s',
'email_exit_status' => 'Exit status code: %s'
);

2346
Core/Libraries/Email.php Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,114 +0,0 @@
<?php
/**
* FuzeWorks.
*
* The FuzeWorks MVC PHP FrameWork
*
* Copyright (C) 2015 TechFuze
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @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 <abel@techfuze.net>
* @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];
}
}

View File

@ -1,55 +0,0 @@
<?php
/**
* FuzeWorks.
*
* The FuzeWorks MVC PHP FrameWork
*
* Copyright (C) 2015 TechFuze
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @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
*/
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

@ -1,50 +0,0 @@
<?php
/**
* FuzeWorks.
*
* The FuzeWorks MVC PHP FrameWork
*
* Copyright (C) 2015 TechFuze
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @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
*/
return array(
'module_class' => '\Module\Mailer\Main',
'module_file' => 'class.mailer.php',
'module_name' => 'Mailer',
'dependencies' => array(),
'aliases' => array(),
'name' => 'Mailer',
'description' => 'PHPMailer wrapper for FuzeWorks',
'author' => 'core',
'version' => '1.0.0',
'website' => 'http://fuzeworks.techfuze.net/',
'date_created' => '08-07-2015',
'date_updated' => '08-07-2015',
);

View File

@ -3,7 +3,6 @@
"php": ">=5.3.0",
"ext-curl": "*",
"ext-json": "*",
"phpmailer/phpmailer": "~5.2",
"smarty/smarty": "~3.1"
},
"require-dev": {