diff --git a/administrator/components/com_config/controller/application/sendtestmail.php b/administrator/components/com_config/controller/application/sendtestmail.php
index 3190f95897e70..fd70e3ca4b859 100644
--- a/administrator/components/com_config/controller/application/sendtestmail.php
+++ b/administrator/components/com_config/controller/application/sendtestmail.php
@@ -36,8 +36,12 @@ public function execute()
$this->app->redirect('index.php');
}
+ $this->app->mimeType = 'application/json';
+ $this->app->setHeader('Content-Type', $this->app->mimeType . '; charset=' . $this->app->charSet);
+ $this->app->sendHeaders();
+
$model = new ConfigModelApplication;
echo new JResponseJson($model->sendTestMail());
- JFactory::getApplication()->close();
+ $this->app->close();
}
}
diff --git a/administrator/components/com_config/view/application/html.php b/administrator/components/com_config/view/application/html.php
index 5c16eea8e8091..84588a2516e11 100644
--- a/administrator/components/com_config/view/application/html.php
+++ b/administrator/components/com_config/view/application/html.php
@@ -73,6 +73,13 @@ public function render()
$this->userIsSuperAdmin = $user->authorise('core.admin');
+ // Add strings for translations in Javascript.
+ JText::script('COM_CONFIG_SENDMAIL_JS_ERROR_CONNECTION_ABORT');
+ JText::script('COM_CONFIG_SENDMAIL_JS_ERROR_NO_CONTENT');
+ JText::script('COM_CONFIG_SENDMAIL_JS_ERROR_OTHER');
+ JText::script('COM_CONFIG_SENDMAIL_JS_ERROR_PARSE');
+ JText::script('COM_CONFIG_SENDMAIL_JS_ERROR_TIMEOUT');
+
$this->addToolbar();
return parent::render();
diff --git a/administrator/language/en-GB/en-GB.com_config.ini b/administrator/language/en-GB/en-GB.com_config.ini
index 028f5edd14be2..91c51b5a33599 100644
--- a/administrator/language/en-GB/en-GB.com_config.ini
+++ b/administrator/language/en-GB/en-GB.com_config.ini
@@ -230,6 +230,11 @@ COM_CONFIG_SAVE_SUCCESS="Configuration successfully saved."
COM_CONFIG_SENDMAIL_ACTION_BUTTON="Send Test Mail"
COM_CONFIG_SENDMAIL_BODY="This is a test mail sent using "_QQ_"%s"_QQ_". If you receive it, then your email settings are correct!"
COM_CONFIG_SENDMAIL_ERROR="Test mail could not be sent."
+COM_CONFIG_SENDMAIL_JS_ERROR_CONNECTION_ABORT="A connection abort has occured while fetching the JSON data."
+COM_CONFIG_SENDMAIL_JS_ERROR_NO_CONTENT="No content was returned."
+COM_CONFIG_SENDMAIL_JS_ERROR_OTHER="An error has occured while fetching the JSON data: HTTP %s status code."
+COM_CONFIG_SENDMAIL_JS_ERROR_PARSE="A parse error has occured while processing the following JSON data:
%s
"
+COM_CONFIG_SENDMAIL_JS_ERROR_TIMEOUT="A timeout has occured while fetching the JSON data."
COM_CONFIG_SENDMAIL_METHOD_MAIL="PHP Mail"
COM_CONFIG_SENDMAIL_METHOD_SENDMAIL="Sendmail"
COM_CONFIG_SENDMAIL_METHOD_SMTP="SMTP"
diff --git a/media/system/js/sendtestmail-uncompressed.js b/media/system/js/sendtestmail-uncompressed.js
index bbe5ae3ff1b3f..f028de02d9ec8 100644
--- a/media/system/js/sendtestmail-uncompressed.js
+++ b/media/system/js/sendtestmail-uncompressed.js
@@ -25,43 +25,77 @@ jQuery(document).ready(function ($)
};
$.ajax({
- url: sendtestmail_url,
- data: email_data
- })
+ method: "POST",
+ url: sendtestmail_url,
+ data: email_data,
+ dataType: "json"
+ })
+ .fail(function (jqXHR, textStatus, error) {
+ var msg = {};
+
+ if (textStatus == 'parsererror')
+ {
+ // Html entity encode.
+ var encodedJson = jqXHR.responseText.trim();
+
+ var buf = [];
+ for (var i = encodedJson.length-1; i >= 0; i--) {
+ buf.unshift( [ '', encodedJson[i].charCodeAt(), ';' ].join('') );
+ }
- .done(function (response)
- {
- var data_response = $.parseJSON(response);
+ encodedJson = buf.join('');
+
+ msg.error = [ Joomla.JText._('COM_CONFIG_SENDMAIL_JS_ERROR_PARSE').replace('%s', encodedJson) ];
+ }
+ else if (textStatus == 'nocontent')
+ {
+ msg.error = [ Joomla.JText._('COM_CONFIG_SENDMAIL_JS_ERROR_NO_CONTENT') ];
+ }
+ else if (textStatus == 'timeout')
+ {
+ msg.error = [ Joomla.JText._('COM_CONFIG_SENDMAIL_JS_ERROR_TIMEOUT') ];
+ }
+ else if (textStatus == 'abort')
+ {
+ msg.error = [ Joomla.JText._('COM_CONFIG_SENDMAIL_JS_ERROR_CONNECTION_ABORT') ];
+ }
+ else
+ {
+ msg.error = [ Joomla.JText._('COM_CONFIG_SENDMAIL_JS_ERROR_OTHER').replace('%s', jqXHR.status) ];
+ }
+
+ Joomla.renderMessages(msg);
+ })
+ .done(function (response) {
var msg = {};
- if (data_response.data)
+ if (response.data)
{
- if (typeof data_response.messages == 'object')
+ if (typeof response.messages == 'object')
{
- if (typeof data_response.messages.success != 'undefined' && data_response.messages.success.length > 0)
+ if (typeof response.messages.success != 'undefined' && response.messages.success.length > 0)
{
- msg.success = [data_response.messages.success];
+ msg.success = [response.messages.success];
}
}
-
}
else
{
- if (typeof data_response.messages == 'object')
+ if (typeof response.messages == 'object')
{
- if (typeof data_response.messages.error != 'undefined' && data_response.messages.error.length > 0)
+ if (typeof response.messages.error != 'undefined' && response.messages.error.length > 0)
{
- msg.error = [data_response.messages.error];
+ msg.error = [response.messages.error];
}
- if (typeof data_response.messages.notice != 'undefined' && data_response.messages.notice.length > 0)
+ if (typeof response.messages.notice != 'undefined' && response.messages.notice.length > 0)
{
- msg.notice = [data_response.messages.notice];
+ msg.notice = [response.messages.notice];
}
- if (typeof data_response.messages.message != 'undefined' && data_response.messages.message.length > 0)
+ if (typeof response.messages.message != 'undefined' && response.messages.message.length > 0)
{
- msg.message = [data_response.messages.message];
+ msg.message = [response.messages.message];
}
}
}
diff --git a/media/system/js/sendtestmail.js b/media/system/js/sendtestmail.js
index fae9cd4daa2a6..558650af7001e 100644
--- a/media/system/js/sendtestmail.js
+++ b/media/system/js/sendtestmail.js
@@ -1,6 +1 @@
-/**
- * @package Joomla.JavaScript
- * @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved.
- * @license GNU General Public License version 2 or later; see LICENSE.txt
- */
-jQuery(document).ready(function(e){e("#sendtestmail").click(function(){var s={smtpauth:e('input[name="jform[smtpauth]"]').val(),smtpuser:e('input[name="jform[smtpuser]"]').val(),smtppass:e('input[name="jform[smtppass]"]').val(),smtphost:e('input[name="jform[smtphost]"]').val(),smtpsecure:e('select[name="jform[smtpsecure]"]').val(),smtpport:e('input[name="jform[smtpport]"]').val(),mailfrom:e('input[name="jform[mailfrom]"]').val(),fromname:e('input[name="jform[fromname]"]').val(),mailer:e('select[name="jform[mailer]"]').val(),mailonline:e('input[name="jform[mailonline]"]:checked').val()};e.ajax({url:sendtestmail_url,data:s}).done(function(s){var m=e.parseJSON(s),a={};m.data?"object"==typeof m.messages&&"undefined"!=typeof m.messages.success&&m.messages.success.length>0&&(a.success=[m.messages.success]):"object"==typeof m.messages&&("undefined"!=typeof m.messages.error&&m.messages.error.length>0&&(a.error=[m.messages.error]),"undefined"!=typeof m.messages.notice&&m.messages.notice.length>0&&(a.notice=[m.messages.notice]),"undefined"!=typeof m.messages.message&&m.messages.message.length>0&&(a.message=[m.messages.message])),Joomla.renderMessages(a)}),window.scrollTo(0,0)})});
+jQuery(document).ready(function(e){e("#sendtestmail").click(function(){var s={smtpauth:e('input[name="jform[smtpauth]"]').val(),smtpuser:e('input[name="jform[smtpuser]"]').val(),smtppass:e('input[name="jform[smtppass]"]').val(),smtphost:e('input[name="jform[smtphost]"]').val(),smtpsecure:e('select[name="jform[smtpsecure]"]').val(),smtpport:e('input[name="jform[smtpport]"]').val(),mailfrom:e('input[name="jform[mailfrom]"]').val(),fromname:e('input[name="jform[fromname]"]').val(),mailer:e('select[name="jform[mailer]"]').val(),mailonline:e('input[name="jform[mailonline]"]:checked').val()};e.ajax({method:"POST",url:sendtestmail_url,data:s,dataType:"json"}).fail(function(e,s){var a={};if("parsererror"==s){for(var o=e.responseText.trim(),m=[],r=o.length-1;r>=0;r--)m.unshift(["",o[r].charCodeAt(),";"].join(""));o=m.join(""),a.error=[Joomla.JText._("COM_CONFIG_SENDMAIL_JS_ERROR_PARSE").replace("%s",o)]}else"nocontent"==s?a.error=[Joomla.JText._("COM_CONFIG_SENDMAIL_JS_ERROR_NO_CONTENT")]:"timeout"==s?a.error=[Joomla.JText._("COM_CONFIG_SENDMAIL_JS_ERROR_TIMEOUT")]:"abort"==s?a.error=[Joomla.JText._("COM_CONFIG_SENDMAIL_JS_ERROR_CONNECTION_ABORT")]:a.error=[Joomla.JText._("COM_CONFIG_SENDMAIL_JS_ERROR_OTHER").replace("%s",e.status)];Joomla.renderMessages(a)}).done(function(e){var s={};e.data?"object"==typeof e.messages&&"undefined"!=typeof e.messages.success&&e.messages.success.length>0&&(s.success=[e.messages.success]):"object"==typeof e.messages&&("undefined"!=typeof e.messages.error&&e.messages.error.length>0&&(s.error=[e.messages.error]),"undefined"!=typeof e.messages.notice&&e.messages.notice.length>0&&(s.notice=[e.messages.notice]),"undefined"!=typeof e.messages.message&&e.messages.message.length>0&&(s.message=[e.messages.message])),Joomla.renderMessages(s)}),window.scrollTo(0,0)})});