diff --git a/admin-dev/themes/default/template/controllers/customer_threads/message.tpl b/admin-dev/themes/default/template/controllers/customer_threads/message.tpl
index 2a6159ad9..c73fe1923 100644
--- a/admin-dev/themes/default/template/controllers/customer_threads/message.tpl
+++ b/admin-dev/themes/default/template/controllers/customer_threads/message.tpl
@@ -48,7 +48,7 @@
diff --git a/classes/Mail.php b/classes/Mail.php
index 11057608c..c8173521e 100644
--- a/classes/Mail.php
+++ b/classes/Mail.php
@@ -32,19 +32,25 @@ include_once(_PS_SWIFT_DIR_.'Swift/Plugin/Decorator.php');
class MailCore
{
+ const TYPE_HTML = 1;
+ const TYPE_TEXT = 2;
+ const TYPE_BOTH = 3;
+
public static function Send($id_lang, $template, $subject, $templateVars, $to,
$toName = null, $from = null, $fromName = null, $fileAttachment = null, $modeSMTP = null, $templatePath = _PS_MAIL_DIR_, $die = false)
{
- $configuration = Configuration::getMultiple(array('PS_SHOP_EMAIL',
- 'PS_MAIL_METHOD',
- 'PS_MAIL_SERVER',
- 'PS_MAIL_USER',
- 'PS_MAIL_PASSWD',
- 'PS_SHOP_NAME',
- 'PS_MAIL_SMTP_ENCRYPTION',
- 'PS_MAIL_SMTP_PORT',
- 'PS_MAIL_METHOD',
- 'PS_MAIL_TYPE'));
+ $configuration = Configuration::getMultiple(array(
+ 'PS_SHOP_EMAIL',
+ 'PS_MAIL_METHOD',
+ 'PS_MAIL_SERVER',
+ 'PS_MAIL_USER',
+ 'PS_MAIL_PASSWD',
+ 'PS_SHOP_NAME',
+ 'PS_MAIL_SMTP_ENCRYPTION',
+ 'PS_MAIL_SMTP_PORT',
+ 'PS_MAIL_METHOD',
+ 'PS_MAIL_TYPE'
+ ));
if (!isset($configuration['PS_MAIL_SMTP_ENCRYPTION'])) $configuration['PS_MAIL_SMTP_ENCRYPTION'] = 'off';
if (!isset($configuration['PS_MAIL_SMTP_PORT'])) $configuration['PS_MAIL_SMTP_PORT'] = 'default';
@@ -192,9 +198,9 @@ class MailCore
$templateVars['{shop_name}'] = Tools::safeOutput(Configuration::get('PS_SHOP_NAME'));
$templateVars['{shop_url}'] = Tools::getShopDomain(true, true).__PS_BASE_URI__;
$swift->attachPlugin(new Swift_Plugin_Decorator(array($to_plugin => $templateVars)), 'decorator');
- if ($configuration['PS_MAIL_TYPE'] == 3 || $configuration['PS_MAIL_TYPE'] == 2)
+ if ($configuration['PS_MAIL_TYPE'] == Mail::TYPE_BOTH || $configuration['PS_MAIL_TYPE'] == Mail::TYPE_TEXT)
$message->attach(new Swift_Message_Part($templateTxt, 'text/plain', '8bit', 'utf-8'));
- if ($configuration['PS_MAIL_TYPE'] == 3 || $configuration['PS_MAIL_TYPE'] == 1)
+ if ($configuration['PS_MAIL_TYPE'] == Mail::TYPE_BOTH || $configuration['PS_MAIL_TYPE'] == Mail::TYPE_HTML)
$message->attach(new Swift_Message_Part($templateHtml, 'text/html', '8bit', 'utf-8'));
if ($fileAttachment && isset($fileAttachment['content']) && isset($fileAttachment['name']) && isset($fileAttachment['mime']))
$message->attach(new Swift_Message_Attachment($fileAttachment['content'], $fileAttachment['name'], $fileAttachment['mime']));
diff --git a/controllers/admin/AdminCustomerThreadsController.php b/controllers/admin/AdminCustomerThreadsController.php
index a2e2c677b..1be15bb64 100644
--- a/controllers/admin/AdminCustomerThreadsController.php
+++ b/controllers/admin/AdminCustomerThreadsController.php
@@ -319,7 +319,7 @@ class AdminCustomerThreadsControllerCore extends AdminController
if ($id_employee && $employee && Validate::isLoadedObject($employee))
{
$params = array(
- '{messages}' => $output,
+ '{messages}' => Tools::nl2br(stripslashes($output)),
'{employee}' => $current_employee->firstname.' '.$current_employee->lastname,
'{comment}' => stripslashes($_POST['message_forward']));
@@ -341,7 +341,7 @@ class AdminCustomerThreadsControllerCore extends AdminController
else if ($email && Validate::isEmail($email))
{
$params = array(
- '{messages}' => $output,
+ '{messages}' => Tools::nl2br(stripslashes($output)),
'{employee}' => $current_employee->firstname.' '.$current_employee->lastname,
'{comment}' => stripslashes($_POST['message_forward']));
diff --git a/controllers/admin/AdminEmailsController.php b/controllers/admin/AdminEmailsController.php
index 78c7b3a67..5daf9e20c 100644
--- a/controllers/admin/AdminEmailsController.php
+++ b/controllers/admin/AdminEmailsController.php
@@ -42,9 +42,36 @@ class AdminEmailsControllerCore extends AdminController
'title' => $this->l('E-mail'),
'icon' => 'email',
'fields' => array(
- 'PS_MAIL_EMAIL_MESSAGE' => array('title' => $this->l('Send e-mail to:'), 'desc' => $this->l('When customers send message from order page'), 'validation' => 'isUnsignedId', 'type' => 'select', 'cast' => 'intval', 'identifier' => 'email_message', 'list' => $arr),
- 'PS_MAIL_METHOD' => array('title' => '', 'validation' => 'isGenericName', 'type' => 'radio', 'required' => true, 'choices' => array(1 => $this->l('Use PHP mail() function. Recommended; works in most cases'), 2 => $this->l('Set my own SMTP parameters. For advanced users ONLY')), 'js' => array(1 => 'onclick="$(\'#smtp\').slideUp();"', 2 => 'onclick="$(\'#smtp\').slideDown();"'), 'visibility' => Shop::CONTEXT_ALL),
- 'PS_MAIL_TYPE' => array('title' => '', 'validation' => 'isGenericName', 'type' => 'radio', 'required' => true, 'choices' => array(1 => $this->l('Send e-mail as HTML'), 2 => $this->l('Send e-mail as Text'), 3 => $this->l('Both'))),
+ 'PS_MAIL_EMAIL_MESSAGE' => array(
+ 'title' => $this->l('Send e-mail to:'),
+ 'desc' => $this->l('When customers send message from order page'),
+ 'validation' => 'isUnsignedId',
+ 'type' => 'select',
+ 'cast' => 'intval',
+ 'identifier' => 'email_message',
+ 'list' => $arr
+ ),
+ 'PS_MAIL_METHOD' => array(
+ 'title' => '',
+ 'validation' => 'isGenericName',
+ 'type' => 'radio',
+ 'required' => true,
+ 'choices' => array(
+ 1 => $this->l('Use PHP mail() function. Recommended; works in most cases'),
+ 2 => $this->l('Set my own SMTP parameters. For advanced users ONLY')
+ ),
+ 'js' => array(
+ 1 => 'onclick="$(\'#smtp\').slideUp();"',
+ 2 => 'onclick="$(\'#smtp\').slideDown();"'
+ ),
+ 'visibility' => Shop::CONTEXT_ALL
+ ),
+ 'PS_MAIL_TYPE' => array('title' => '', 'validation' => 'isGenericName', 'type' => 'radio', 'required' => true, 'choices' => array(
+ Mail::TYPE_HTML => $this->l('Send e-mail as HTML'),
+ Mail::TYPE_TEXT => $this->l('Send e-mail as Text'),
+ Mail::TYPE_BOTH => $this->l('Both')
+ )
+ ),
),
'submit' => array()
),
@@ -54,12 +81,70 @@ class AdminEmailsControllerCore extends AdminController
'top' => '',
'bottom' => '
',
'fields' => array(
- 'PS_MAIL_DOMAIN' => array('title' => $this->l('Mail domain:'), 'desc' => $this->l('Fully qualified domain name (keep it empty if you do not know)'), 'empty' => true, 'validation' => 'isUrl', 'size' => 30, 'type' => 'text', 'visibility' => Shop::CONTEXT_ALL),
- 'PS_MAIL_SERVER' => array('title' => $this->l('SMTP server:'), 'desc' => $this->l('IP or server name (e.g., smtp.mydomain.com)'), 'validation' => 'isGenericName', 'size' => 30, 'type' => 'text', 'visibility' => Shop::CONTEXT_ALL),
- 'PS_MAIL_USER' => array('title' => $this->l('SMTP user:'), 'desc' => $this->l('Leave blank if not applicable'), 'validation' => 'isGenericName', 'size' => 30, 'type' => 'text', 'visibility' => Shop::CONTEXT_ALL),
- 'PS_MAIL_PASSWD' => array('title' => $this->l('SMTP password:'), 'desc' => $this->l('Leave blank if not applicable'), 'validation' => 'isAnything', 'size' => 30, 'type' => 'password', 'visibility' => Shop::CONTEXT_ALL, 'autocomplete' => false),
- 'PS_MAIL_SMTP_ENCRYPTION' => array('title' => $this->l('Encryption:'), 'desc' => $this->l('Use an encrypt protocol'), 'type' => 'select', 'cast' => 'strval', 'identifier' => 'mode', 'list' => array(array('mode' => 'off', 'name' => $this->l('None')), array('mode' => 'tls', 'name' => $this->l('TLS')), array('mode' => 'ssl', 'name' => $this->l('SSL'))), 'visibility' => Shop::CONTEXT_ALL),
- 'PS_MAIL_SMTP_PORT' => array('title' => $this->l('Port:'), 'desc' => $this->l('Number of port to use'), 'validation' => 'isInt', 'size' => 5, 'type' => 'text', 'cast' => 'intval', 'visibility' => Shop::CONTEXT_ALL),
+ 'PS_MAIL_DOMAIN' => array(
+ 'title' => $this->l('Mail domain:'),
+ 'desc' => $this->l('Fully qualified domain name (keep it empty if you do not know)'),
+ 'empty' => true, 'validation' =>
+ 'isUrl', 'size' => 30,
+ 'type' => 'text',
+ 'visibility' => Shop::CONTEXT_ALL
+ ),
+ 'PS_MAIL_SERVER' => array(
+ 'title' => $this->l('SMTP server:'),
+ 'desc' => $this->l('IP or server name (e.g., smtp.mydomain.com)'),
+ 'validation' => 'isGenericName',
+ 'size' => 30,
+ 'type' => 'text',
+ 'visibility' => Shop::CONTEXT_ALL
+ ),
+ 'PS_MAIL_USER' => array(
+ 'title' => $this->l('SMTP user:'),
+ 'desc' => $this->l('Leave blank if not applicable'),
+ 'validation' => 'isGenericName',
+ 'size' => 30,
+ 'type' => 'text',
+ 'visibility' => Shop::CONTEXT_ALL
+ ),
+ 'PS_MAIL_PASSWD' => array(
+ 'title' => $this->l('SMTP password:'),
+ 'desc' => $this->l('Leave blank if not applicable'),
+ 'validation' => 'isAnything',
+ 'size' => 30,
+ 'type' => 'password',
+ 'visibility' => Shop::CONTEXT_ALL,
+ 'autocomplete' => false
+ ),
+ 'PS_MAIL_SMTP_ENCRYPTION' => array(
+ 'title' => $this->l('Encryption:'),
+ 'desc' => $this->l('Use an encrypt protocol'),
+ 'type' => 'select',
+ 'cast' => 'strval',
+ 'identifier' => 'mode',
+ 'list' => array(
+ array(
+ 'mode' => 'off',
+ 'name' => $this->l('None')
+ ),
+ array(
+ 'mode' => 'tls',
+ 'name' => $this->l('TLS')
+ ),
+ array(
+ 'mode' => 'ssl',
+ 'name' => $this->l('SSL')
+ )
+ ),
+ 'visibility' => Shop::CONTEXT_ALL
+ ),
+ 'PS_MAIL_SMTP_PORT' => array(
+ 'title' => $this->l('Port:'),
+ 'desc' => $this->l('Number of port to use'),
+ 'validation' => 'isInt',
+ 'size' => 5,
+ 'type' => 'text',
+ 'cast' => 'intval',
+ 'visibility' => Shop::CONTEXT_ALL
+ ),
),
'submit' => array()
),
@@ -67,7 +152,12 @@ class AdminEmailsControllerCore extends AdminController
'title' => $this->l('Test your e-mail configuration'),
'icon' => 'email',
'fields' => array(
- 'PS_SHOP_EMAIL' => array('title' => $this->l('Send a test e-mail to'), 'type' => 'text', 'size' => 40, 'id' => 'testEmail'),
+ 'PS_SHOP_EMAIL' => array(
+ 'title' => $this->l('Send a test e-mail to'),
+ 'type' => 'text',
+ 'size' => 40,
+ 'id' => 'testEmail'
+ ),
),
'bottom' => '',
diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php
index 7db4ef14f..1c2bd0dca 100755
--- a/controllers/admin/AdminOrdersController.php
+++ b/controllers/admin/AdminOrdersController.php
@@ -345,7 +345,7 @@ class AdminOrdersControllerCore extends AdminController
else
{
$message = $customer_message->message;
- if (Configuration::get('PS_MAIL_TYPE') != 2)
+ if (Configuration::get('PS_MAIL_TYPE') != Mail::TYPE_TEXT)
$message = Tools::nl2br($customer_message->message);
$varsTpl = array(
diff --git a/controllers/front/ContactController.php b/controllers/front/ContactController.php
index 16226fcfc..874444e65 100644
--- a/controllers/front/ContactController.php
+++ b/controllers/front/ContactController.php
@@ -50,7 +50,7 @@ class ContactControllerCore extends FrontController
$message = Tools::htmlentitiesUTF8(Tools::getValue('message'));
if (!($from = trim(Tools::getValue('from'))) || !Validate::isEmail($from))
$this->errors[] = Tools::displayError('Invalid e-mail address');
- else if (!($message = Tools::nl2br($message)))
+ else if (!$message)
$this->errors[] = Tools::displayError('Message cannot be blank');
else if (!Validate::isCleanHtml($message))
$this->errors[] = Tools::displayError('Invalid message');
@@ -119,7 +119,7 @@ class ContactControllerCore extends FrontController
{
$mail_var_list = array(
'{email}' => $from,
- '{message}' => stripslashes($message),
+ '{message}' => Tools::nl2br(stripslashes($message)),
'{id_order}' => (int)Tools::getValue('id_order'),
'{attached_file}' => $_FILES['fileUpload']['name'] ? $_FILES['fileUpload']['name'] : '');
diff --git a/controllers/front/OrderDetailController.php b/controllers/front/OrderDetailController.php
index ea0cf868f..458388264 100644
--- a/controllers/front/OrderDetailController.php
+++ b/controllers/front/OrderDetailController.php
@@ -86,7 +86,7 @@ class OrderDetailControllerCore extends FrontController
else
$ct = new CustomerThread((int)$id_customer_thread);
$cm->id_customer_thread = $ct->id;
- $cm->message = Tools::htmlentitiesutf8(Tools::nl2br($msgText));
+ $cm->message = Tools::htmlentitiesutf8($msgText);
$cm->ip_address = ip2long($_SERVER['REMOTE_ADDR']);
$cm->add();
@@ -103,11 +103,12 @@ class OrderDetailControllerCore extends FrontController
if (Validate::isLoadedObject($customer))
Mail::Send($this->context->language->id, 'order_customer_comment', Mail::l('Message from a customer'),
array(
- '{lastname}' => $customer->lastname,
- '{firstname}' => $customer->firstname,
- '{email}' => $customer->email,
- '{id_order}' => (int)($order->id),
- '{message}' => $msgText),
+ '{lastname}' => $customer->lastname,
+ '{firstname}' => $customer->firstname,
+ '{email}' => $customer->email,
+ '{id_order}' => (int)($order->id),
+ '{message}' => Tools::nl2br($msgText)
+ ),
$to, $toName, $customer->email, $customer->firstname.' '.$customer->lastname);
if (Tools::getValue('ajax') != 'true')