Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion public/include/autoloader.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
die('Unable to load your coins class definition for ' . $config['algorithm']);
}

// Swiftmailer
require_once(INCLUDE_DIR . '/lib/swiftmailer/swift_required.php');

// Detect device
if ( PHP_SAPI == 'cli') {
// Create a new compile folder just for crons
Expand Down Expand Up @@ -70,4 +73,4 @@
require_once(INCLUDE_DIR . '/lib/Michelf/Markdown.php');
require_once(INCLUDE_DIR . '/lib/scrypt.php');

?>
?>
42 changes: 33 additions & 9 deletions public/include/classes/mail.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,50 @@ public function contactform($senderName, $senderEmail, $senderSubject, $senderMe
}

/**
* Send a mail with templating via Smarty
* Send a mail with templating via Smarty and Siftmailer
* @param template string Template name within the mail folder, no extension
* @param aData array Data array with some required fields
* SUBJECT : Mail Subject
* subject : Mail Subject
* email : Destination address
**/
public function sendMail($template, $aData) {
// Make sure we don't load a cached filed
// Prepare SMTP transport and mailer
$transport_type = $this->config['swiftmailer']['type'];
if ($transport_type == 'sendmail') {
$transport = Swift_SendmailTransport::newInstance($this->config['swiftmailer'][$transport_type]['path'] . ' ' . $this->config['swiftmailer'][$transport_type]['options']);
} else if ($this->config['swiftmailer']['type'] == 'smtp') {
$transport = Swift_SmtpTransport::newInstance($this->config['switfmailer']['smtp']['host'], $this->config['switfmailer']['smtp']['port'], $this->config['switfmailer']['smtp']['encryption']);
if (!empty($this->config['switfmailer']['smtp']['username']) && !empty($this->config['switfmailer']['smtp']['password'])) {
$transport->setUsername($this->config['switfmailer']['smtp']['username']);
$transport->setPassword($this->config['switfmailer']['smtp']['password']);
}
}
$mailer = Swift_Mailer::newInstance($transport);
// Prepare the smarty templates used
$this->smarty->clearCache(BASEPATH . 'templates/mail/' . $template . '.tpl');
$this->smarty->clearCache(BASEPATH . 'templates/mail/subject.tpl');
$this->smarty->assign('WEBSITENAME', $this->setting->getValue('website_name'));
$this->smarty->assign('SUBJECT', $aData['subject']);
$this->smarty->assign('DATA', $aData);
$headers = 'From: ' . $this->setting->getValue('website_name') . '<' . $this->setting->getValue('website_email') . ">\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

// Create new message for Swiftmailer
$message = Swift_Message::newInstance()
->setSubject($this->smarty->fetch(BASEPATH . 'templates/mail/subject.tpl'))
->setFrom(array( $this->setting->getValue('website_email') => $this->setting->getValue('website_name')))
->setTo($aData['email'])
->setSender($this->setting->getValue('website_email'))
->setReturnPath($this->setting->getValue('website_email'))
->setBody($this->smarty->fetch(BASEPATH . 'templates/mail/' . $template . '.tpl'), 'text/html');
if (strlen(@$aData['senderName']) > 0 && @strlen($aData['senderEmail']) > 0 )
$headers .= 'Reply-To: ' . $aData['senderName'] . ' <' . $aData['senderEmail'] . ">\n";
if (mail($aData['email'], $this->smarty->fetch(BASEPATH . 'templates/mail/subject.tpl'), $this->smarty->fetch(BASEPATH . 'templates/mail/' . $template . '.tpl'), $headers, '-f ' . $this->setting->getValue('website_email')))
return true;
$message->setReplyTo(array($aData['senderEmail'] => $aData['senderName']));

// Send message out with configured transport
try {
if ($mailer->send($message)) return true;
} catch (Exception $e) {
$this->setErrorMessage($e->getMessage());
return false;
}
$this->setErrorMessage($this->sqlError('E0031'));
return false;
}
Expand Down
14 changes: 14 additions & 0 deletions public/include/config/global.inc.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@
$config['wallet']['username'] = 'testnet';
$config['wallet']['password'] = 'testnet';

/**
* Swiftmailer configuration
* Configure your way to send mails
* https://github.com/MPOS/php-mpos/wiki/Config-Setup#wiki-swiftmailer
**/
$config['swiftmailer']['type'] = 'sendmail';
$config['swiftmailer']['sendmail']['path'] = '/usr/sbin/sendmail';
$config['swiftmailer']['sendmail']['options'] = '-bs';
$config['switfmailer']['smtp']['host'] = 'your.mail-relay.com';
$config['switfmailer']['smtp']['port'] = '587';
$config['switfmailer']['smtp']['encryption'] = 'tls';
$config['switfmailer']['smtp']['username'] = '';
$config['switfmailer']['smtp']['password'] = '';

/**
* Getting Started Config
* Shown to users in the 'Getting Started' section
Expand Down
81 changes: 81 additions & 0 deletions public/include/lib/swiftmailer/classes/Swift.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

/*
* This file is part of SwiftMailer.
* (c) 2004-2009 Chris Corbyn
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

/**
* General utility class in Swift Mailer, not to be instantiated.
*
* @package Swift
*
* @author Chris Corbyn
*/
abstract class Swift
{
public static $initialized = false;
public static $inits = array();

/** Swift Mailer Version number generated during dist release process */
const VERSION = '5.1.0';

/**
* Registers an initializer callable that will be called the first time
* a SwiftMailer class is autoloaded.
*
* This enables you to tweak the default configuration in a lazy way.
*
* @param mixed $callable A valid PHP callable that will be called when autoloading the first Swift class
*/
public static function init($callable)
{
self::$inits[] = $callable;
}

/**
* Internal autoloader for spl_autoload_register().
*
* @param string $class
*/
public static function autoload($class)
{
// Don't interfere with other autoloaders
if (0 !== strpos($class, 'Swift_')) {
return;
}

$path = dirname(__FILE__).'/'.str_replace('_', '/', $class).'.php';

if (!file_exists($path)) {
return;
}

require $path;

if (self::$inits && !self::$initialized) {
self::$initialized = true;
foreach (self::$inits as $init) {
call_user_func($init);
}
}
}

/**
* Configure autoloading using Swift Mailer.
*
* This is designed to play nicely with other autoloaders.
*
* @param mixed $callable A valid PHP callable that will be called when autoloading the first Swift class
*/
public static function registerAutoload($callable = null)
{
if (null !== $callable) {
self::$inits[] = $callable;
}
spl_autoload_register(array('Swift', 'autoload'));
}
}
73 changes: 73 additions & 0 deletions public/include/lib/swiftmailer/classes/Swift/Attachment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

/*
* This file is part of SwiftMailer.
* (c) 2004-2009 Chris Corbyn
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

/**
* Attachment class for attaching files to a {@link Swift_Mime_Message}.
*
* @package Swift
* @subpackage Mime
* @author Chris Corbyn
*/
class Swift_Attachment extends Swift_Mime_Attachment
{
/**
* Create a new Attachment.
*
* Details may be optionally provided to the constructor.
*
* @param string|Swift_OutputByteStream $data
* @param string $filename
* @param string $contentType
*/
public function __construct($data = null, $filename = null, $contentType = null)
{
call_user_func_array(
array($this, 'Swift_Mime_Attachment::__construct'),
Swift_DependencyContainer::getInstance()
->createDependenciesFor('mime.attachment')
);

$this->setBody($data);
$this->setFilename($filename);
if ($contentType) {
$this->setContentType($contentType);
}
}

/**
* Create a new Attachment.
*
* @param string|Swift_OutputByteStream $data
* @param string $filename
* @param string $contentType
*
* @return Swift_Mime_Attachment
*/
public static function newInstance($data = null, $filename = null, $contentType = null)
{
return new self($data, $filename, $contentType);
}

/**
* Create a new Attachment from a filesystem path.
*
* @param string $path
* @param string $contentType optional
*
* @return Swift_Mime_Attachment
*/
public static function fromPath($path, $contentType = null)
{
return self::newInstance()->setFile(
new Swift_ByteStream_FileByteStream($path),
$contentType
);
}
}
Loading